Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to match specific string followed by number?

Tags:

What regular expression can I use to find this?

&v=15151651616 

Where &v= is a static string and the number part may vary.

like image 288
Miguel Antunes Avatar asked Jul 10 '12 10:07

Miguel Antunes


People also ask

How do you match a regular expression with digits?

To match any number from 0 to 9 we use \d in regex. It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range.

How do I match a specific character in regex?

Match any specific character in a setUse square brackets [] to match any characters in a set. Use \w to match any single alphanumeric character: 0-9 , a-z , A-Z , and _ (underscore). Use \d to match any single digit. Use \s to match any single whitespace character.

What does ?= Mean in regex?

?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).


2 Answers

"^&v=[0-9]+$" if you want at least 1 number or "^&v=[0-9]*$" if no number must match too.

If you want it to match inside another sequence just remove the ^ and $, which means the sequence beginning by (^) and sequence ending with ($)

like image 104
Maresh Avatar answered Sep 22 '22 20:09

Maresh


You can use the following regular expression:

&v=\d+ 

This matches &v= and then one or more digits.

like image 20
Simeon Visser Avatar answered Sep 22 '22 20:09

Simeon Visser