【问题标题】:javascript string pattern match gave null resultjavascript字符串模式匹配给出了空结果
【发布时间】:2013-04-04 07:40:30
【问题描述】:
var listing = "<a name=\"id43ba766a68\" class=\"id\"></a>";
var hexid = listing.match(/name=\"id([a-f0-9]+)\"/);

我的 hexid 是 null。这里有什么问题?

我使用正则表达式测试器http://www.regextester.com/ 对其进行了测试,它只是按预期返回。

【问题讨论】:

  • 它对我很有效 - 返回:["name="id43ba766a68"", "43ba766a68"]
  • 在这里完美运行。

标签: javascript regex string-matching


【解决方案1】:
var listing = "<a name=\"id43ba766a68\" class=\"id\"></a>";
var hexid = listing.match(/name=\"id([a-f0-9]+)\"/);

对我来说工作正常:http://jsfiddle.net/nM8Vv/

【讨论】:

    猜你喜欢
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-04
    • 2015-11-18
    相关资源
    最近更新 更多