RegEx flavor: wxRegEx.
I am trying to create a "grouped" regex that matches a string that sometimes begins with a whitespace. When it doesn't begin with a whitespace, it begins with the target group (second parenthesized expression in the following sample). It is a relatively simple line made of a few predictable tokens and one portion of arbitrary text, e.g.
"good: Sed ut perspiciatis unde omnis iste natus error "
"better: Sit voluptatem accusantium doloremque laudantium "
"best: Nemo enim ipsam voluptatem quia voluptas "
" ok: Sit voluptatem accusantium doloremque laudantium "
Note: The quoted characters are not part of my input. By introducing the quotes in my posting I am trying to make the boundaries of each line/string clearer.
The regex that I came up with to match the above in a "grouped" manner (i.e. that I can address each group separately for further processing) is:
(^\s*)(good|better|best|ok)(: )(.*)( $)
Note: \s is wxRegEx's class-shorthand escape for [[:space:]].
The problem is that this regex works only when the line actually begins with a space. Why? doesn't the '*' right after '\s' mean "0 or more occurrences of \s" ?
I know I am missing something fundamental here, but what is it?
Have you tried this with (^ *)
instead of (^\s*)
? Is it possible you're wrong about the \s
syntax? I don't know wxRegEx myself.