相关疑难解决方法(0)

如何使这个正则表达式不会导致"灾难性的回溯"?

我正在尝试使用我从http://daringfireball.net/2010/07/improved_regex_for_matching_urls获得的匹配正则表达式的URL

(?xi)
\b
(                       # Capture 1: entire matched URL
  (?:
    https?://               # http or https protocol
    |                       #   or
    www\d{0,3}[.]           # "www.", "www1.", "www2." … "www999."
    |                           #   or
    [a-z0-9.\-]+[.][a-z]{2,4}/  # looks like domain name followed by a slash
  )
  (?:                       # One or more:
    [^\s()<>]+                  # Run of non-space, non-()<>
    |                           #   or
    \(([^\s()<>]+|(\([^\s()<>]+\)))*\)  # balanced parens, up to 2 levels
  )+
  (?:                       # End with:
    \(([^\s()<>]+|(\([^\s()<>]+\)))*\)  # balanced parens, up to 2 levels
    |                               # …
Run Code Online (Sandbox Code Playgroud)

javascript regex backtracking

6
推荐指数
1
解决办法
1208
查看次数

标签 统计

backtracking ×1

javascript ×1

regex ×1