Forum Moderators: coopster

Message Too Old, No Replies

Regular Expressions: match all but one character

         

zRonin

10:20 pm on Mar 11, 2006 (gmt 0)

10+ Year Member



Can reguluar expressions match all but one character?

I know you can use w/ for words and . for everything, but I want to match all but ". I tried doing the following:

[\.\:\,\;\*\(\!\?\'\)\/\\\$\%\&\+\-\_\#\’A-z0-9 ]+

in order to match all common punctuation, spaces, letters, and numbers, but I realized it wont work for letters with accents and other special characters.

I would really like a way to match everything except the " character.

zRonin

1:54 am on Mar 12, 2006 (gmt 0)

10+ Year Member



I found the answer:

You can match the characters not within a range by complementing the set. This is indicated by including a "^" as the first character of the class; "^" elsewhere will simply match the "^" character. For example, [^5] will match any character except "5".

coopster

1:34 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Glad you got it sorted. The circumflex (^) can mean different things when used in different pattern-matching methods but you are right, when used in the very first position of the character class it negates. The PCRE [php.net] pages are loaded with information on how to structure patterns.