0

我正在尝试解析链接'bit.ly/KATlrT'asdfs asdf as dfa sdf a bit.ly/KATlrT f sf sd f dsfdsa

这是我正在使用的正则表达式,但它不匹配?

bit?/S+
4

3 回答 3

3
(bit\.ly\/\S+)
^\ /^^\/^^\/^^
| | ||| ||| ||
| | ||| ||| |`- End first capture group
| | ||| ||| `-- Match 1 or more of previous (any non-space character)
| | ||| ||`---- Match any non-space character
| | ||| |`----- Match '/' literally because of previous escape character
| | ||| `------ Escape next special character
| | ||`-------- Match 'ly' literally
| | |`--------- Match '.' literally because of previous escape character
| | `---------- Escape next special character
| `------------ Match 'bit' literally
`------------- Start first capture group

在行动中看到它。


您在问题中提供的解释:

bit?/S+
\/^^^^^
| |||||
| ||||`- repeat previous ('S') 1 or more times
| |||`-- match 'S' literally
| ||`--- this is not escaped, and will cause problems
| |`---- previous is optional ('t')
| `----- match 't' literally 
`------- match 'bi' literally

如果你想了解更多关于正则表达式的信息,www.regular-expressions.info是一个很好的资源,RegexrRubular是测试你的正则表达式的好工具。

于 2012-06-16T18:18:48.427 回答
0

由于我不懂语言,我将发布 Java 正则表达式的答案(主要基于 Perl 正则表达式)。有相当多的语言或多或少地遵循 Perl 的正则表达式语法。

"bit\\.ly/[a-zA-Z]+"
于 2012-06-16T18:17:24.327 回答
0

它不匹配可能是因为您忘记了 escape \S,所以它寻找一个文字S。此外,您将需要.而不是?大多数语言。

尝试bit\.\S+orbit\.ly\/\S+等​​。

于 2012-06-16T18:19:19.863 回答