我正在学习正则表达式,遇到了一个问题。我有以下内容:
href="http://google.com/topic/713725-dogs-are-great-3"> href="http://google.com/topic/213225-humans-are-great"> href="http://google.com/topic/342315-cats-are-great-but-small">
用这段代码href="(?:[^"]*)topic/([^<]*)">
i can select
713725-dogs-are-great-3 213225-humans-are-great 342315-cats-are-great-but-small
但是我只想匹配数字
342315213225713725
任何想法?
对于显示的示例和尝试,请尝试以下正则表达式;这将创建一个捕获组,您可以使用它来捕获匹配的值。
bhref="(?:[^"]*)topic/(d+)-.*">$
正则表达式的在线演示
解释:为以上内容添加详细说明。
bhref=" ##Matching href using b before it as a word boundary followed by =" here.
(?:[^"]*)topic/ ##In a non-capturing group matching till " everything till topic/
(d+) ##Creating 1st capturing group which has digits in it.
-.*">$ ##Matching everything till " followed by "> till end of value.