Given this string the symbol for four is 4 like in 34. _1234_
. How can regex match the individual 4
and the 4
in 34
but not the one between the two _
characters in _1234_
.
(?<!_\d*)4(?!\d*_)
It makes sure the 4
is neither followed nor follows any count of digits and then an underscore.
Edit: I'm sorry, this won't work because JS does not support negative lookbehinds.
Your requirements are not very specific, so sorry if this will not work in practice for the actual application.
/(?:(?:^|\b)[^\_][a-zA-Z0-9]*)(4)(?:[a-zA-Z0-9\.]*[^\_](?:\b|$))/g
It checks every word that it does not begin and end with underscores for a 4.
Look for _\\d+_|(4)
, and check for a match with the (4) group. Since the alternatives in | are tried left-to-right, the (4) group will only match 4s that aren't in numbers surrounded by underscores
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.