Welcome to WebmasterWorld Guest from 3.214.184.124

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Regular Expressions: match all but one character

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

Junior Member

10+ Year Member

joined:June 7, 2005
posts:53
votes: 0


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.

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

Junior Member

10+ Year Member

joined:June 7, 2005
posts:53
votes: 0


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".

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

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12555
votes: 3


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.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members