Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex-transformation with text and numbers

I am having troubles making my regex-statement to work as intended.

Regex statement: ([a-z][a-z\d]+)(?=([A-Z][a-z\d]+))

Starting string: regex2Hard4Me

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

current result: REGEX2_HARD4_ME

desirable result: REGEX_2_HARD_4_ME

Any help is highly appreciated.

>Solution :

You can match a single char a-z or digit, and assert a char A-Z or digit to the right:

[a-z0-9](?=[A-Z0-9])

In the replacement use the full match followed by an underscore.

Regex demo

Output

regex_2_Hard_4_Me

Then uppercase the string to get REGEX_2_HARD_4_ME

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading