Help with RegEx and csv file

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
sg94k6r2
Posts: 5
Joined: Fri Nov 14, 2003 3:44 pm

Help with RegEx and csv file

Post by sg94k6r2 »

My CSV file contains lines like these..

"A","234234","7UM*","2345","00070","12343","120 DEL J.NORRIS"
"B","23423","8UM*","2345","00070","12343","120 DEL J.IMTIH"
"V","1234","6UM*","2345","00070","12343","ABCDEFG"
"V","1234","6UM*","2345","00070","12343",""

I want to find rows where last column (eg. "120 DEL J.NORRIS") contains any numeric values i.e. 1st and 2nd row but not 3rd and 4th row

Is this possible via RegEx?

Thank you very much
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

This matches the distinctive parts of the lines you're interested in:
[0-9][^"]*"$

This matches the entire lines you're interested in:
^.*[0-9][^"]*"$
sg94k6r2
Posts: 5
Joined: Fri Nov 14, 2003 3:44 pm

Post by sg94k6r2 »

Thank you very much! that did the trick! now I have to figure out how it really works ; )
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

[0-9][^"]*"$ matches

Code: Select all

1.    [0-9]         any digit

2.    [^"]*         a string not containing double quotes, that is:
2.1     [^"]          any character except double quote
2.2     *             repeated any number (possibly zero) of times

3.    "             a double quote

4.    $             the end of a line
The $ anchors the match to the end of the line. So the regex matches if a line contains a digit and ends with a " , and there is no intervening " between that digit and that final ". The regex matches everything from the digit to the end of the line (but not the newline itself).

^.*[0-9][^"]*"$ matches

Code: Select all

1.    ^             the beginning of a line

2     .*            any string within a line, that is:
2.1     .             any character except newline
2.2     *             repeated any number (possibly zero) of times

3.    [0-9][^"]*"$  as above
So this regex matches any whole line containing what the first regex matches.
Post Reply