Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图在以下单引号之间获取一个字符串document.write('mystring')我尝试了以下模式\'[A-Za-z0-9]+\',但我想要没有单引号的字符串。我怎样才能做到这一点?
document.write('mystring')
\'[A-Za-z0-9]+\'
preg_match("/'([a-z0-9]+)'/i", $str, $matches); //string contents are now in `$matches[1]`
您可能还想使用\w甚至其他东西来进行捕获,除非您绝对确定要获取的字符串是纯字母数字的。这也假设只使用撇号而不是引号。
\w
捕获特定组中的单词:
\'([A-Za-z0-9]+)\'