Click here to Skip to main content
14,930,906 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
GeneralRe: Parsing ASCII-Only string Pin
Marco Bertschi7-Feb-14 1:50
professionalMarco Bertschi7-Feb-14 1:50 
GeneralRe: Parsing ASCII-Only string Pin
Richard Deeming7-Feb-14 2:04
mveRichard Deeming7-Feb-14 2:04 
QuestionRe: Parsing ASCII-Only string Pin
Marco Bertschi7-Feb-14 2:08
professionalMarco Bertschi7-Feb-14 2:08 
AnswerRe: Parsing ASCII-Only string Pin
Richard Deeming7-Feb-14 2:14
mveRichard Deeming7-Feb-14 2:14 
GeneralRe: Parsing ASCII-Only string Pin
Marco Bertschi7-Feb-14 2:33
professionalMarco Bertschi7-Feb-14 2:33 
QuestionParsing a string with match groups Pin
Dominick Marciano23-Aug-13 9:47
professionalDominick Marciano23-Aug-13 9:47 
AnswerRe: Parsing a string with match groups Pin
Matt T Heffron28-Oct-13 11:33
professionalMatt T Heffron28-Oct-13 11:33 
AnswerRe: Parsing a string with match groups Pin
Gabriel Szabo7-Nov-13 21:27
MemberGabriel Szabo7-Nov-13 21:27 
You can use the alternation syntax "(a|b)". A match in your case is an expression in form "parameter=value", or an operator. Operator can be "or" or "and" and must have a space before and after.

Following pattern produces the results you wanted. For an input string "Name=John or Name=Jane and Date=Now" you get matches "Name=John", " or ", "Name=Jane", " and ", "Date=Now":
"(\w+=\w+|\s(or|and)\s)"

If you want to use regex for validation only, you can do it this way (note that you get only a single match with this pattern):
Regex.IsMatch(inputStr, "^(\w+=\w+|\s(or|and)\s)+$");

And you can go even further with validation. Following pattern uses positive look ahead/behind syntax to ensure that operators are enclosed with valid expressions:
Regex.IsMatch(inputStr, "^(\w+=\w+|(?<=\w+=\w+)\s(or|and)\s(?=\w+=\w+))+$");

Gabriel Szabo


modified 8-Nov-13 3:57am.

QuestionMatching a string. Pin
Septimus Hedgehog19-Aug-13 4:48
MemberSeptimus Hedgehog19-Aug-13 4:48 
AnswerRe: Matching a string. Pin
PIEBALDconsult19-Aug-13 5:03
professionalPIEBALDconsult19-Aug-13 5:03 
GeneralRe: Matching a string. Pin
Septimus Hedgehog19-Aug-13 5:27
MemberSeptimus Hedgehog19-Aug-13 5:27 
GeneralRe: Matching a string. Pin
PIEBALDconsult19-Aug-13 5:31
professionalPIEBALDconsult19-Aug-13 5:31 
GeneralRe: Matching a string. Pin
Septimus Hedgehog19-Aug-13 5:44
MemberSeptimus Hedgehog19-Aug-13 5:44 
GeneralRe: Matching a string. Pin
PIEBALDconsult19-Aug-13 9:01
professionalPIEBALDconsult19-Aug-13 9:01 
GeneralRe: Matching a string. Pin
Septimus Hedgehog19-Aug-13 23:04
MemberSeptimus Hedgehog19-Aug-13 23:04 
QuestionHelp wanted with regex format. Pin
Septimus Hedgehog31-Jul-13 3:17
MemberSeptimus Hedgehog31-Jul-13 3:17 
AnswerRe: Help wanted with regex format. Pin
Richard Deeming31-Jul-13 3:47
mveRichard Deeming31-Jul-13 3:47 
GeneralRe: Help wanted with regex format. Pin
Septimus Hedgehog31-Jul-13 3:53
MemberSeptimus Hedgehog31-Jul-13 3:53 
AnswerRe: Help wanted with regex format. Pin
OriginalGriff31-Jul-13 4:10
mveOriginalGriff31-Jul-13 4:10 
GeneralRe: Help wanted with regex format. Pin
Septimus Hedgehog31-Jul-13 4:34
MemberSeptimus Hedgehog31-Jul-13 4:34 
GeneralRe: Help wanted with regex format. Pin
OriginalGriff31-Jul-13 4:40
mveOriginalGriff31-Jul-13 4:40 
GeneralRe: Help wanted with regex format. Pin
Septimus Hedgehog31-Jul-13 5:15
MemberSeptimus Hedgehog31-Jul-13 5:15 
GeneralRe: Help wanted with regex format. Pin
Bernhard Hiller31-Jul-13 22:26
MemberBernhard Hiller31-Jul-13 22:26 
GeneralRe: Help wanted with regex format. Pin
Septimus Hedgehog31-Jul-13 23:58
MemberSeptimus Hedgehog31-Jul-13 23:58 
GeneralRe: Help wanted with regex format. Pin
Bernhard Hiller1-Aug-13 20:39
MemberBernhard Hiller1-Aug-13 20:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.