RegEx for a line containing NOT contains two different lines

Well, you gurus know you know Regex!

How do you use reg ex to search for a string to make sure that it does not contain any of two different lines.

Example: Let's say I want to make sure that "FileNTile" does not contain File or Tile

thanks

cnorr

+7
regex
source share
2 answers
^((?!File|Tile).)*$ 

This is unlikely to be a good idea. Almost every programming environment will have a clearer and more efficient approach when matching strings. (e.g. Python: if 'File' not in s and 'Tile' not in s )

Also, not all regular expression implementations have the form. eg. It is not reliable in JavaScript. And there may be problems with new lines depending on the mode (multi-line, dot-up flags).

+11
source share

It depends on the language. The easiest way (conceptually): to search for both, and not to match. In Ruby:

 s = "FileNTile" (s !~ /File/) and (s !~ /Tile) # true if s is free of files and tiles. 
0
source share

All Articles