我有一个字符串:
"whatever( here i com ( asdfasDF ( ) ) ) go home"
我想提取第一个"("
和最后一个")"
之间的所有内容,即:
" here i com ( asdfasDF ( ) ) "
什么是一个好的正则表达式来提取它?
更新:
如果我的字符串包含换行符,则以下操作有效:
/((([.|s|S])*))/
带有捕获的贪婪表达式,例如:
/((.*))/
"whatever( here i com ( asdfasDF ( ) ) ) go home"[/((.*))/m, 1]
或
"whatever( here i com ( asdfasDF ( ) ) ) go home"[/(?<=().*(?=))/m]
str = "whatever( here i com ( asdfasDF ( ) ) ) go home"
p str[str.index("(")+1..str.rindex(")")-1]