Ytria logo DOCUMENTATION
⚠ This page requires javascript enabled in browser
Global Features / Regular expressions / Examples

 

Using Regex for specific filter: Exclude a string

In this example we want to exclude everything that contains the string server.

To do this, we will use the following Regular Expression:

^((?!.*server.*).)*$

Breakdown of Regex elements used

^Beginning of the string
()Capturing Group
(?!)Negative look ahead. Specifies a group that cannot match after the main expression.
(i.e. if it matches, then the result is discarded)
.Matches any character except line breaks
*Match 0 or more of the preceding token
serverString
$End of the string
NoteYou can get the same result by excluding each character of the string.

^((?![s][e][r][v][e][r]).)*$

^Beginning of the string
()Capturing Group
(?!)Negative look ahead. Specifies a group that cannot match after the main expression.
(i.e. if it matches, then the result is discarded)
[]Matches any character in the set
sCharacter
eCharacter
rCharacter
vCharacter
eCharacter
rCharacter
.Matches any character except line breaks
*Match 0 or more of the preceding token
$End of the string

Practical case

In this example we will use Filter by Regular Expression to exclude everything that contains the string server in the Type column.



Click on the filter icon and select Filter By Regular Expression.





Having used the expression ^((?!.*server.*).)*$ to filter the column, all lines that contained the string server have now been excluded.



Tip Excluding multiple strings:

If you need to exclude two or more strings, like server and person, you can use the following Regex:

^((?!.*(server|person).*).)*$

^Beginning of the string
()Capturing Group
(?!)Negative look ahead. Specifies a group that cannot match after the main expression.
(i.e. if it matches, then the result is discarded)
.Matches any character except line breaks
*Match 0 or more of the preceding token
serverString
|Match either the expression before or after
personString
$End of the string

Using the following Regex gives the same result.

^((?!.*server.*)(?!.*person.*).)*$