Regex for string contains?

What is a regular expression for a simple check, does the string contain a specific word (for example, "Test")? I have done some searches, but cannot get a direct example of such a regular expression. This is for building a script, but has nothing to do with any particular programming language.

+90
regex
Feb 15 '11 at 1:16
source share
4 answers

Assuming PCRE-style regular expressions:

If you want to test it as a single, complete word, it \bTest\b , with appropriate flags for case insensitivity, if necessary, and delimiters for your programming language. \b represents the "word boundary", that is, the point between the characters where the word can be considered the start or end. For example, since spaces are used to separate words, there will be a word boundary on each side of the space.

If you want to test it as part of a word, it's just Test , again with the appropriate flags for case insensitivity. Please note that the commonly used β€œsubstring” methods are faster in this case because they eliminate the overhead of regular expression analysis.

+70
Feb 15 '11 at 1:22
source share

Just don't snap your template:

 /Test/ 

The above regex will check that the literal string "Test" is somewhere inside it.

+87
Feb 15 '11 at 1:18
source share

I put together the various elements to get the confirmation needed for the students' emails. I hope this works, I have not fully verified.

 ^[a-zA-Z0-9._%+-]+@\{ac|org|stu|student|stud|studmail|edu|uni} 
+1
Jun 17 '19 at 13:59
source share

I’m several years late, but why isn’t that so?

 [Tt][Ee][Ss][Tt] 
-7
Jul 22 '14 at 15:21
source share



All Articles