Is it possible using only regex to limit the number of occurrences of specific characters in a string?
For example, I want to limit the number of occurrences of $ or % or space in a string to 5 occurrences max.
Is this possible?
try this expression. In this case, the character you're limiting is A
/^([^A]*A[^A]*){0,5}$/
http://rubular.com/r/X5iz5dHzgs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With