Home:ALL Converter>Boolean logic in a single regular expression - possible?

Boolean logic in a single regular expression - possible?

Ask Time:2009-11-12T08:01:00         Author:MicMit

Json Formatter

Can we put into a single regular expression , boolean logic : line starts with 'a' or 'b' . Question is triggered by using FileHelpers utility which does have a text box "Record Condition Selector" for "ExcludeIfMatchRegex" . Utility is written in C#. ^a - works , just don't how write down ^a OR ^b

Author:MicMit,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1718946/boolean-logic-in-a-single-regular-expression-possible
Gyuri :

How about this: ^[ab]",
2009-11-12T00:02:26
Jed Smith :

Having a hard time understanding you, but...if you're looking for a match if the string starts with \"a\" or \"b\", and a fail otherwise, you could do this:\n\n^(a|b)(.+)$\n\n\nThen, when you get the match's groups, the first group will be either an \"a\" or \"b\" and the second group will be the rest of the string.",
2009-11-12T00:02:39
Robert P :

use the | (pipe) feature:\n\n^a|^b\n\n\nOr, in extended formatting:\n\n^a # starts with an A\n| # OR\n^b # starts with a B\n",
2009-11-12T00:02:42
yy