【问题标题】:RegExp find soundcloud linkRegExp 查找 soundcloud 链接
【发布时间】:2013-12-24 23:38:59
【问题描述】:

我正在尽力设计一个聊天,我希望它找到 soundcloud 链接并将它们变成可以播放歌曲的播放器。我知道如何为播放器使用他们的 API,但我的 RegExp 无法正常工作。

我的代码:/https:\/\/soundcloud\.com\//gi 只找到 soundcloud 位,但我也希望它找到斜杠之后的所有内容,直到它碰到空格。

【问题讨论】:

    标签: javascript regex hyperlink chat soundcloud


    【解决方案1】:

    but I also want it to find everything that comes after the slash until it hits whitespace.

    那么你可以使用:

    /https?:\/\/soundcloud\.com\/\S*/gi
    

    \S* 将匹配 https://soundcloud.com/ 段之后的 0 个或多个非空格字符

    【讨论】:

    • 这将捕获链接后的任何标点符号。句点、逗号、分号、圆括号、方括号等
    • @idbehold:请阅读 OP 所说的问题:I also want it to find everything that comes after the slash until it hits whitespace.
    • 他想要将聊天中的 soundcloud 链接变成 iframe 播放器。在正则表达式中捕获标点符号很可能会破坏该功能。 OP 可能会说他想在斜线之后捕获所有内容,直到空格,但这肯定不是他需要的。
    猜你喜欢
    • 2019-09-27
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多