The first time I work with regular expressions.

There is a regular session: ([AZ]{1,1})[az]{2,9}_([AZ]{1,1})[az]{2,9}

How to make capital letters be only: the first letter in a line and the first after _ ?

Now it works on MaXim_Ivanov , it is only necessary that it works on Maxim_Ivanov

  • one
    Is the text arbitrary or what? - Sergey
  • @ Sergey, yes, arbitrary. - Maxim

2 answers 2

 ^[AZ][az]+_[AZ][az]+$ 

{1,1} - not needed

^ - beginning of line

$ - end of line

+ - 1 or more characters

Test: http://www.phpliveregex.com/p/j8b

  • And if in the middle of the line? - Sergey
  • @ Sergey, as I understand it, it is not necessary - Crantisz
  • Text is arbitrary, but oh well) Answer is accepted - Sergey

As an option, you can add a word border symbol.

 \b[AZ][az]{2,9}_[AZ][az]{2,9}