Link to home
Start Free TrialLog in
Avatar of GivenRandy
GivenRandy

asked on

RegEx - More Requirements

Releated to earlier question(s):

https://www.experts-exchange.com/questions/22034295/RegEx-Remove-Trailing-Spaces-on-Line.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
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi GivenRandy;

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

Fernando
Avatar of GivenRandy
GivenRandy

ASKER

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. :)
You do not need to replace \t with any other character?
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Touche!
Glad I was able to help. ;=)