标签: regex
http://regex101.com/r/nT6oO6
此正则表达式:'([^']+?)\'.someMethod\(\)
'([^']+?)\'.someMethod\(\)
匹配'Hello World "xaxaxaxa" xx'.someMethod()
'Hello World "xaxaxaxa" xx'.someMethod()
我可以轻松地将"Hello World 'xaxaxaxa' xx".someMethod()的内容与单独的正则表达式进行匹配,稍加修改。如何使用单个正则表达式匹配这些字符串的内容?
"Hello World 'xaxaxaxa' xx".someMethod()
答案 0 :(得分:1)
您可以将两个regexes合并在一起来实现:
regexes
(\'([^']+?)\'.someMethod\(\)|\"([^"]+?)\".someMethod\(\))
DEMO
答案 1 :(得分:1)
您可以使用此正则表达式:
(["'])(.+?)(?=\1\.someMethod\(\))
并使用matched group #2即$2
matched group #2
$2