Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

RegEx - More Requirements

Posted on 2006-10-23
8
Medium Priority
?
260 Views
Last Modified: 2010-05-18
Releated to earlier question(s):

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_22034295.html

Starting fresh, with some additional requirements. There are a bunch of lines, ending with with "\r\n", that are in a long string. The replacement string needs to:

+ remove "//" and anything after it (could also see just "//\r\n", with no text on line after the "//")
+ remove tab ("\t") characters
+ remove blank lines (either with OR without whitespace before the "\r\n")
+ remove leading whitespace at beginning of line
+ remove trailing whitespace at end of line
0
Comment
Question by:GivenRandy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17790256
Hi GivenRandy;

Whe you say, "remove tab ("\t") characters", That is all \t in the string data?

Fernando
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 17790274
Right, all of the \t in the whole string. Just delete them.

Right now, I have like 5 lines of code to do this and trying to reduce to one. Not just for analysis-paralysis, but to help learn RegEx in the background. :)
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17790308
You do not need to replace \t with any other character?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Author Comment

by:GivenRandy
ID: 17790389
Correct. It gets stripped. It was a carryover from a tab-delimited file, but the tabs are not significant -- it now is space separated and newlines.
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 17790404
Something like this at the moment:

        cleanedText = Regex.Replace(cleanedText, "[\t]", String.Empty)

I used the brackets because there had been other characters in the set as well. Now, just the tab.
0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 17792067
Hi GivenRandy;

The only way that I can come up with a pattern that you want without making multiple regex calls is the following.

        ' I took the pattern out of the call itself to make the code more readable
        Dim pattern As String = "^\s*\r\n|^\s*//.*?\r\n|^(?<1>\r\n)*\s*(?<3>.*?)" & _
            "\s*//.*?(?<4>\r\n)|^(?<1>\r\n)*\s*(?<3>.*?)(?<4>\r\n)"

        Dim cleanedText As String = Regex.Replace(originalText, pattern, "$3$4", _
            RegexOptions.Multiline).Replace(Chr(9), "")

As you can see from the call to parse the string the replacement of the tab char is done after the string is returned from regex.

Fernando
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 17794914
Touche!
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17795583
Glad I was able to help. ;=)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question