Reputation: 19
I am learning regex and ran into a problem. I have the following:
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">
with this code
href="(?:[^"]*)topic/([^<]*)">
i can select
713725-dogs-are-great-3 213225-humans-are-great 342315-cats-are-great-but-small
but i only want to match the numbers
342315 213225 713725
any ideas?
Upvotes: 0
Views: 59
Reputation: 133428
With your shown samples and attempts, please try following regex; which will create 1 capturing group which you can use to grab the matched value.
\bhref="(?:[^"]*)topic\/(\d+)-.*">$
Explanation: Adding detailed explanation for above.
\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.
Upvotes: 3