Search code examples
regexqtphp-uft

How can i write a regular expression for to match string staring with alphabets and ending with digits


i want to match the strings which is listed below other than than that whatever the string is it should not match

rahul2803
albert1212
ra456
r1

only the above mentioned strings should match in the following group of data

rahul
2546rahul
456
rahul2803
albert1212
ra456
r1
rahulrenjan
r4ghyk

i tried with ([a-z]*[0-9]) but it's not working.


Solution

  • In regular expressions * means zero or more so your regex matches zero letters. If you want one or more use + (\d means digit).

    ^[a-zA-Z]+\d+$