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?
如何制作表达式,以便必须至少有1个双引号或至少1个单引号?
3 个解决方案
#1
5
This should do the work:
这应该做的工作:
@"(?:\s*('|\")+\s*)"
#2
2
Try this expression:
试试这个表达式:
(?:\\s*[\\"\\']\\s*)
:D
#3
2
If you mean you want to find one single or one double quote then just put both inside a character group and don't put a question mark after it.
如果您的意思是想要找到一个单引号或一个双引号,那么只需将它们放在一个字符组中,并且不要在它后面添加问号。
(?:\s*[\"']\s*)
If you mean 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*)
#1
5
This should do the work:
这应该做的工作:
@"(?:\s*('|\")+\s*)"
#2
2
Try this expression:
试试这个表达式:
(?:\\s*[\\"\\']\\s*)
:D
#3
2
If you mean you want to find one single or one double quote then just put both inside a character group and don't put a question mark after it.
如果您的意思是想要找到一个单引号或一个双引号,那么只需将它们放在一个字符组中,并且不要在它后面添加问号。
(?:\s*[\"']\s*)
If you mean 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*)