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.
假设我有以下 js 代码:
r='d|daa|dd'; reg = /\|.*/; result = reg.exec(r);
这将返回|daa|dd,但我想要的是daa|dd。
|daa|dd
daa|dd
正则表达式应该是什么?谢谢
分组是要走的路:
reg = /\|(.*)/;
它将搜索以 | 开头的字符串,但将单独捕获组(括在括号中)以供进一步使用。
r='d|daa|dd'; reg = /\|(.*)/; result = reg.exec(r);
result[1]然后填充捕获组中的内容。
result[1]