PDA

View Full Version : Regular expression search error



jwebsmall
September 12th, 2011, 07:38 PM
Sorry I made a mistake. I should have written

^{[^\t]+}\t{[^\t]+}\t{[^\t]+}\t.*$

instead of what I wrote below:


search for

^{[^\t]+}\t{[^t]+}\t{[^\t]+}\t.*$

in this data

1ABX BARRICK GOLD CORP (Amer Flex) 25000000 EF
1ACGL ARCH Capital Group Ltd (Amer Fl 22500000 EF
1AON AON CORPORATION (Amer Flex) 25000000 EF


The second line is not found because the
"(" in the data confuses the RE search evidently.
Each line has tab delimiters.

ian binnie
September 12th, 2011, 08:09 PM
search for

^{[^\t]+}\t{[^t]+}\t{[^\t]+}\t.*$



I have not tried this (any tabs would be stripped from your example).

It depends on exactly what you are trying to do.

To me this looks like:-
a line starting with a string, followed by a tab
a string NOT containing 't' (I suspect not what you mean), followed by a tab
a string, followed by a tab
the rest of the line

Also you should not be using '{' or '}' for groups but '(' or ')'
I assume the groups are for later use.

PS The RE seems unnecessarily complex.
I am always reluctant to suggest RE without testing, as writing them is more an art rather than a science, but try:-
^(.+)\t(.+)\t(.+)\t.*$

jwebsmall
September 12th, 2011, 08:54 PM
I left off the \ in {[^t]+} which should have been {[^\t]+}