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 to exclude one character only once and then should allow it

Regex that I tried:

[+1]?[^0-9],

[+1{1}]?[^0-9],

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

[^+1]?[^0-9]+ – this allows all 1‘s

Sample number :
+1 (634) 841-4313

target :
6348414313

it should remove characters:
+1 () -

my regex removes :
+1 () 1-1

Can any of you help me here with this?

>Solution :

^\+1\D*|\D

This will remove "+1" at the start of the string, then any non-numeric character following it

Given "+1 (987) 6543-2101"
Returns "98765432101"

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