I have a question though. I am new to regular expressions, and I am
confused as to what the "(?i" Stands for?
I prefer not to use Regex Options in my programming code. As I re-use
Regular Expressions, I don't want to have to remember what options to turn
on. Since the Regular Expressions syntax contains modifiers that supply
these options, I use them in the expressions.
It would not compile while I kept the grouping <word> in the
expression. I removed it, and it worked. How could I modify it, so it
(?i)(?:\s*OR\s*)?"([^"]*)"
On closer examination, I determined that my original was not robust enough.
The above should work well for you. Here's the explanation:
(?:\s*OR\s*)?
The word "OR" may precede the rest of the match, but is optional (may appear
0 or 1 times), and may have 0 or more spaces before and after it. It is in a
non-capturing group with the quantifier '?' indicating 0 or 1 times.
"([^"]*)
This is a capturing group (I removed the label, which would make it a named
capturing group). It indicates a quote character followed by 0 or more
non-quote characters, followed by a quote character. This way, there may be
any characters between the quotes.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
I have a question though. I am new to regular expressions, and I am
confused as to what the "(?i" Stands for?
It would not compile while I kept the grouping <word> in the
expression. I removed it, and it worked. How could I modify it, so it
would also pass if I wanted to pass test data like below:
Test Data : "test1" OR "My Test Data2"
It is failing when I include a space in between the quoted words.
Regex regex = new Regex(@" (?i?\s)(?:\s*OR\s*)?""");
passed = regex.IsMatch(TestData);- Hide quoted text -
- Show quoted text -