-1

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.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156

2 Answers2

2

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+$
Motti
  • 110,860
  • 49
  • 189
  • 262
0

Regular expressions are fun to solve once you get the hang of the syntax.

This one should be pretty straight:

  1. Start with a letter. ^[a-z] (I am not taking the case of capital letters here, if they are then ^[a-zA-Z] )

  2. Have multiple letters/digits in between .*

  3. End the string with a digit [0-9]$

Combine all 3 and you get:

^[a-z].*[0-9]$
Ankur Jain
  • 236
  • 1
  • 8