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.
我正在尝试使用正则表达式从字符串中查找字符串的一部分,
所以说例如我的字符串是:
string = "Hello my name is carl how are you doing?";
我想匹配“carl”这个名字,我该怎么做呢?
这就是我得到的,
.*?(?=\show)
我的问题与文本“你好,我的名字是”不匹配
干杯
卡尔
试一试\w+(?=\show):
\w+(?=\show)
> var string = "Hello my name is carl how are you doing?"; > /\w+(?=\show)/.exec(string) ["carl"]
var m = myStr.match(/(\w+) how are you doing\?/) if (m) { name = m[1]; }