Regex find at least one of two characters

Bring me, I'm new to regular expressions, so my syntax may be a little broken.

Here is my expression:

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

This means: any number of spaces, then the possibility of a double quote, then the possibility of a single quote, then any number of spaces.

The problem is that this is the same anyway, 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 one single quote?

+4
source share
3 answers

This should do the job:

 @"(?:\s*('|\")+\s*)" 
+5
source

Try the following expression:

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

: D

+2
source

If you mean that you want to find one or two double quotes, just put them inside a group of characters and do not put a question mark after it.

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

If you mean that you want 1 or more single quotes or 1 or more double quotes

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

If you mean you want 1 or more single or double quotes

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

+2
source

All Articles