【问题标题】:Extract text from textarea which was in between @ and # symbol [duplicate]从@和#符号之间的textarea中提取文本[重复]
【发布时间】:2015-12-23 06:12:56
【问题描述】:

我想从 @ 和 # 符号之间的 textarea 中提取文本,因为我正在使用下面的正则表达式。

\B@(\w*)$/

但是,当分隔符之间有空格时,不会得到预期的结果。

例如

"Welcome to the company @first name last name# We all wished."

我的输出应该是:

first name last name

【问题讨论】:

    标签: jquery regex textarea


    【解决方案1】:

    试试这个

    var regex = /\@(.*?)\#/;
    var str="Welcome to the company @first name last name# We all wished.";
    var matched = regex.exec(str);
    console.log(matched[1])
    

    【讨论】:

      【解决方案2】:

      您可以使用 /@(.*?)#/ 匹配 @# 之间的任何内容

      var str = "Welcome to the company @first name last name# We all wished.";
      var res = str.match(/@(.*)#/)[1];
      document.write(res);

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-19
        相关资源
        最近更新 更多