Lab Lab Lab Lab - 1 year ago 70
C# Question

How to match a complete inputted string that contains a 'word' and a 'number xx' using RegEx?

I mean, I need to check if the string contains a word and a number in the following order:

wordXX
. For example,
fruit23
and regex returns true. Else if string like
fru103
Regex will return false. Hope, anyone's help me.

Answer Source

Try this regex:

^[a-zA-Z]+\\d{2}$


Or simply:

^word\\d{2}$


Upd:

To match from instance1 to instance99 you have to use:

^instance[1-9]{1}\\d?$

Example: https://ideone.com/tuijJY

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download