给定一个字符串,例如:
示例字符串与要匹配的预期嵌套字符串。
如何隔离仅知道其前缀和后缀的子字符串,例如之间intended
and to match
?
使用正则表达式非捕获括号 https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions#Using_Special_Characters,像这样:
string = 'example string with an intended nested string to match.';
regexp = /(?:intended)(.*)(?:to match)/;
firstMatch = regexp.exec(string)[1]; // " nested string "
问号在正则表达式中有多种用途,括号问号冒号形式(?:
更多正则表达式)
is the 非捕获括号 https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions#Using_Special_Characters.
请参阅 MDN 了解更多详细信息exec() https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/RegExp/exec, 细绳。match() https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/match, and 常用表达 https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)