Why is this RegEx not working correctly?

I have this RegEx here:

/^function(\d)$/

      

It matches function(5)

, but not function(55)

. Why?

+2


a source to share


3 answers


The other posters are correct regarding the +, but what language are you using to parse the regex? Don't you need to hide ()? Otherwise, it must fix the digit (s).

I would have thought that you need ...



/^function\(\d+\)$/

      

+6


a source


/^function(\d+)$/

You need to add +

to make \ d (digits) greedy - match as much as possible. (Assuming this is what you want as it will probably match

function(3242345235234235235234234234535325234235235234523)

, and function(55)



Repeats the previous element one or more times. Greedy so that as many items as possible will be matched before attempting permutations with fewer matches of the previous item, up to the point where the previous item is matched only once.

referring to +

http://www.regular-expressions.info/reference.html

+5


a source


Because you only gave one \d

. If you want to combine more than one digit, please let us know.

0


a source







All Articles