【发布时间】:2015-12-23 06:12:56
【问题描述】:
我想从 @ 和 # 符号之间的 textarea 中提取文本,因为我正在使用下面的正则表达式。
\B@(\w*)$/
但是,当分隔符之间有空格时,不会得到预期的结果。
例如
"Welcome to the company @first name last name# We all wished."
我的输出应该是:
first name last name
【问题讨论】:
我想从 @ 和 # 符号之间的 textarea 中提取文本,因为我正在使用下面的正则表达式。
\B@(\w*)$/
但是,当分隔符之间有空格时,不会得到预期的结果。
例如
"Welcome to the company @first name last name# We all wished."
我的输出应该是:
first name last name
【问题讨论】:
试试这个
var regex = /\@(.*?)\#/;
var str="Welcome to the company @first name last name# We all wished.";
var matched = regex.exec(str);
console.log(matched[1])
【讨论】:
您可以使用 /@(.*?)#/ 匹配 @ 和 # 之间的任何内容
var str = "Welcome to the company @first name last name# We all wished.";
var res = str.match(/@(.*)#/)[1];
document.write(res);
【讨论】: