schmutzler schmutzler - 1 year ago 86
PHP Question

Exclude delimiter from regular expression

I'm pretty new at regular expressions.
For a string like this:


I have created this regular expression:


This puts out 3 matches:

  • "

  • Username;

  • 23456

Why is
not negating the semicolon, but instead removing one digit and how can I fix this? Thanks.

Answer Source

Your ([^\r\n]*?) can eat the ;, so the [^;] is free to take a digit (because it will match anything except the ;).

You probably wanted ; (without [^ ]:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download