Answer the question
In order to leave comments, you need to log in
How to write a regular expression (equal to "[Tt][Ee][Xx][Tt]" and not equal to "text")?
You need to find occurrences of a word that has uppercase letters, but there were no words written entirely in lowercase.
For example, you need to find the word "TeXt" with different letter cases ([Tt][Ee][Xx][Tt]), but not to find the word "text" because it is in lowercase
Text - true
TeXt - true
teXt
- true
TEXT - true
text - false
add
.
Answer the question
In order to leave comments, you need to log in
Through a negative lookbehind/lookahead assertion:
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import re
test = """Text - true
TeXt - true
teXt - true
TEXT - true
text - false"""
reg1 = re.compile(ur"([Tt][Ee][Xx][Tt])(?<!text)")
reg2 = re.compile(ur"(?!text)([Tt][Ee][Xx][Tt])")
print reg1.findall(test)
print reg2.findall(test)
Z:\>test.py
['Text', 'TeXt', 'teXt', 'TEXT']
['Text', 'TeXt', 'teXt', 'TEXT']
Not exactly what you need.
There is some text, but you need to search not for all words (with large and small letters), but for a specific search word that occurs, but not in lower case.
match /\s(test)\s/i && not match /\stest\s/
php:
if (preg_match_all('/\s(test)\s/i', $text, $matches) && !preg_match('/\stest\s/', $text)) {
print_r($matches);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question