Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex find at least one of two characters

Tags:

c#

.net

regex

Bear with me, I am new to regular expressions, so my syntax may be slightly out.

Here is my expression:

"(?:\\s*[\"]?[']?\\s*)"

Which equates to: Any amount of white space, then the possibility of a double quote, then the possibility of a single quote, then any amount of white space.

The problem I have is that this still matches even if there is no double quote or single quote.

How do I make my expression so that there must be at least 1 double quote OR at least 1 single quote?

like image 289
Matthew Layton Avatar asked Nov 21 '25 11:11

Matthew Layton


2 Answers

This should do the work:

@"(?:\s*('|\")+\s*)"
like image 94
Stefano Altieri Avatar answered Nov 23 '25 03:11

Stefano Altieri


Try this expression:

(?:\\s*[\\"\\']\\s*)

:D

like image 23
Dave Bish Avatar answered Nov 23 '25 03:11

Dave Bish