gpt4 book ai didi

javascript - 正则表达式匹配正斜杠对,但不转义或在后续 http ://之间

转载 作者:行者123 更新时间:2023-12-02 17:09:34 24 4
gpt4 key购买 nike

我正在尝试构建一个可以匹配成对正斜杠的正则表达式(例如 /something/),但跳过转义对(例如 \/something\/ )并跳过后续 URL 之类的内容(例如 http://something.com 和 http://somethingelse.org)。

因此,在下面的示例中,只有文本“jumped over”会被匹配,其他任何内容都不会匹配:

The quick brown fox /jumped over/ the lazy dogs. He was looking for a \/website\/ to help him find ways around the dogs because he was sick of \/jumping\/ over them. Unfortunately, both http://routesaroundlazydogs.com/ and https://maps.lazydogs.com/stuff/things/findmap.aspx were both down on the day he was looking.

正则表达式必须在 Javascript 中工作(即没有后向查找)。

最佳答案

  (^|\s+)/([A-Z0-9a-z ]+)/\s+

Regular expression visualization

Debuggex Demo

关于javascript - 正则表达式匹配正斜杠对,但不转义或在后续 http ://之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24944966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com