I'm trying to write a regex to match strings containing four consecutive digits not followed by the character p
.
This is what I have: \\d\\d\\d\\d
But I don't want the regex to match strings such as 1111p
. How can I improve my regex?
/(\\d{4})(?!p)/
will capture all groups of four digits that aren't followed by the character p
. The {}
is a quantifier that allows you to specify a minimum, maximum, or exact number of repetitions and the (?!)
is a special non-capturing group called a “negative lookahead” .
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.