regex question

  • Thread starter Thread starter GS
  • Start date Start date
G

GS

I tried this regex expression but no luck
(?<AcctName>\w*(\s\w*)*((\'s\w\w*){0,1}))\s\[(?<AcctNbr>\d*)\]
with regexoption of mulit-line, explicit capture, ignorecase, dotall and
ignore pattern white space
on data like
PRESIDENT'S CHOICE [0991234]
I got "S CHOICE" for AcctName instead of "PRESIDENT'S CHOICE"

what did I make the mistake?
 
Hello GS,
I tried this regex expression but no luck
(?<AcctName>\w*(\s\w*)*((\'s\w\w*){0,1}))\s\[(?<AcctNbr>\d*)\]
with regexoption of mulit-line, explicit capture, ignorecase, dotall
and
ignore pattern white space
on data like
PRESIDENT'S CHOICE [0991234]
I got "S CHOICE" for AcctName instead of "PRESIDENT'S CHOICE"
what did I make the mistake?

\'s should've been ' I guess.

What is the total input you're trying to parse? If you're just looking for
both parts you could do the following:

(?<AcctName>[^\[]+)\s\[(?<AcctNbr>\d*)]

It just looks for any character that isn't [.

You might even use string.Split and pass it a char[] containing '[' and ']'
to split the string in two parts. It would be much faster.

Jess
 
GS said:
I tried this regex expression but no luck
(?<AcctName>\w*(\s\w*)*((\'s\w\w*){0,1}))\s\[(?<AcctNbr>\d*)\]
with regexoption of mulit-line, explicit capture, ignorecase, dotall and
ignore pattern white space
on data like
PRESIDENT'S CHOICE [0991234]
I got "S CHOICE" for AcctName instead of "PRESIDENT'S CHOICE"

what did I make the mistake?

You only allow an apostrophe in the last word. Also you require the
apostrophe to be followed by an 's' and require another character to
follow the 's'.
 
than you all

I got the following
(?<AcctName>\w*,{0,1}(\s\w*('s){0,1},{0,1})*)\s\[(?<AcctNbr>\d*)\]
to work without capturing every name like phrases.
 
Back
Top