Search code examples
regexregex-group

REGEX - Conditional replacement stopping to match when I choose the new string


I have a lot of developer's name like this:

/Ramon/ /Cesar/ /Murilo/ /Tiago/

I would like to apply a conditional regex to replace every name with just its first letter.

So when it matches /Ramon/ it would become /r/, /Cesar/ turn into /c/...

I'm trying to achive it here: https://regex101.com/r/rTlS1k/3

With no success.

Appreciate any help.

Thanks.


Solution

  • Assuming you are using PCRE based on your regex101, then search for:

    /\/(\w)[^\/]+\//g
    

    and replace with

    /\L\1/
    

    As seen here: https://regex101.com/r/ZDQlEY/1