Link to home
Start Free TrialLog in
Avatar of toddvoros
toddvorosFlag for United States of America

asked on

How to have Regular expression keep first 14 characters and start changes at character 15 or beyond

I need a regular expression that keeps the first 14 characters of a string intact with no changes.  However, if there is a hypen in character 15 or beyond, remove the hypen and all text past the hypen.  If the string is 14 characters or less, do nothing.
Any help on this is greatly appreciated.
Avatar of Hans Langer
Hans Langer

just get the first group of this regular expression:

/(\d{14})(\-.*)?/

You can test it in this amazing tool:

https://regex101.com/r/kP0sI1/2
ASKER CERTIFIED SOLUTION
Avatar of FishMonger
FishMonger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial