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

Remove all matching characters from the beginning of word

I have this regex:

string.replace(/[~!@#$%^&`*()_\+={}[\]|"':;?,\/><,\\]|-+$|-+(?=\.)|\s|^[.]/g, '')

and I have this string: .....domain@#@#$-.com

I want to return domain.com. It works almost fine but it removes only first dot at the beginning, but I want to remove any of dot if it appeal here.

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

I added something like that ^[.], but I think that I miss $ or + sign. But any of my approach doesn’t work. Any ideas?

>Solution :

You have to add the * to ^[.] at the end of your pattern, [.] this means match only one literal dot. * means match zero or more literal dot from the start of the string . so it will be ^[.]*.

[~!@#$%^&`*()_\+={}[\]|"':;?,\/><,\\]|-+$|-+(?=\.)|\s|^[.]*

See regex demo

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