@thg435 wrote this answer to a javascript question:
> a = \"foo 1234567890 bbb 123456\"
\"foo 1234567890 bbb 123456\"
> a.replace(/\\d(?=\\d\\d(\\d{3})
Oddly, I'm experiencing the opposite behavior from you (the first one doesn't work and the other two do), but how about if you replaced the \b
with (?![\u0660-\u0669])
? Then it seems to work no matter what's before or after it:
[\u0660-\u0669](?=[\u0660-\u0669][\u0660-\u0669]([\u0660-\u0669]{3})*(?![\u0660-\u0669]))
Edit: This seems to work for the new requirement - to only add the brackets if the run of digits is 3 digits long or more:
[\u0660-\u0669](?=[\u0660-\u0669]{2}([\u0660-\u0669]{3})+(?![\u0660-\u0669]))|(?<=[\u0660-\u0669]{2})[\u0660-\u0669](?=[\u0660-\u0669]{2}(?![\u0660-\u0669]))
Incidentally, some Regex processors will treat those digits as a match for \d
. Here is that second Regex with \d
instead of those character ranges, which should be a little easier to read:
\d(?=\d{2}(\d{3})+(?!\d))|(?<=\d{2})\d(?=\d{2}(?!\d))