In ColdFusion, I am trying to match and remove 4 to 6 consecutive digits from a string. The string looks something like this:
ABC1234DEFGH or ABCDEF123456
The string is limited to 20 characters and will only contain numbers and letters. The digits are always consecutive and can occur anywhere after the first character of the string. There will only be one occurrence of consecutive digits. If there are fewer than 4 or greater than 6 digits, I want to keep them.
So, for example, if I have a string like this:
ABC1234DEFGH
The desired result will be ABCDEFGH.
For this string:
A123BCDEFGH
The desired result will be A123BCDEFGH.
For this string:
ABCDE1234567FG
The desired result is ABCDE1234567FG.
I tried the suggestion in this post : Regular expression for number with length of 4, 5 or 6 but it doesn't quite cover my requirements.
The suggestion is: [0-9]{4,6}
This expression will remove ANY string with 4 to 6 digits, so if the string has 7 digits, it will remove 6 of them, but I want to keep all 7 digits. I don't know how to create a regular expression that will ONLY match strings of exactly 4, 5, or 6 consecutive digits.
I will greatly appreciate any and all help. (Thanks to ifm for the formatting edit.)
Aucun commentaire:
Enregistrer un commentaire