I can't seem to figure out how to compose a regular expression (used in Javascript) that does the following:
Match all strings where the characters after the 4th character do not contain "GP".
Some example strings:
I'd love some help here...
Use zero-width assertions:
if (subject.match(/^.{4}(?!.*GP)/)) {
    // Successful match
}
Explanation:
"
^        # Assert position at the beginning of the string
.        # Match any single character that is not a line break character
   {4}   # Exactly 4 times
(?!      # Assert that it is impossible to match the regex below starting at this position (negative lookahead)
   .     # Match any single character that is not a line break character
      *  # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
   GP    # Match the characters “GP” literally
)
"
                        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