I need to have a regular expression to restrict the number of digits in a string which may contain alphabets or any other characters along with digits. Is this possible with regular expressions ?
Asked
Active
Viewed 151 times
1 Answers
0
The idea is to anchor beginning and end of string and allow exactly n repetitions of a digit with something else. For example, exactly 6 digits in a string:
^\D*(\d\D*){6}$
![](../../users/profiles/240443.webp)
Amadan
- 169,219
- 18
- 195
- 256