S
S
Sererator2011-04-15 16:21:08
PHP
Sererator, 2011-04-15 16:21:08

PHP + RegExp, character range search with exception

Hello. Please tell me how to write the regular expression [az[^sgm]] in php (non-working example), i.e. all characters from range az except characters sgm?

I found something similar with character classes ( www.php.net/manual/ru/regexp.reference.character-classes.php ): [12[:^digit:]], but I need certain characters, not classes.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
L
lashtal, 2011-04-16
@Serator

The expression is called Double Negative:
[^[:^lower:]sgm]

D
Dzuba, 2011-04-15
@Dzuba

Something like this:[a-f,h-l,n-r,t-z]

D
Dzuba, 2011-04-15
@Dzuba

What if you use conditional subpatterns ? For example:(?(?=[a-z])[^sgm])

Y
yadeveloper, 2011-04-15
@yadeveloper

(?![cde])[a-z]

H
hayk, 2011-04-15
@hayk

Well, actually it's not PHP, but PCRE. And it's most likely not possible.

A
Alexey Shein, 2011-04-16
@conf

You can try this:
/^[^\Wsgm]+$/
Explanation: \W means all characters not included in the word, ^ inverts this class, i.e. \W becomes \w and also excludes sgm characters following \W from the current class.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question