Regular expressions (REGEX)

You can use regular expressions as a data type in a predicate (the WHERE clause). This is useful if you want to compare a value with the regular expression to check for a match.

You can try the following examples against your own data in the GoToAssist search field, or against fictitious data in the Query Sandbox:


Example 1

Query: Find all instances of Microsoft Office.

SELECT name 
FROM /network/device/wmi/win32_product 
WHERE name = ?Microsoft.*Office?

Results: Depending on the database, the results look similar to this:

row
   name Microsoft Office Visio Professional 2003
row
   name Microsoft Office Small Business Edition 2003
row
   name Microsoft Office Excel MUI (English) 2007 
   . . .

Example 2

Query: Find all IP addresses starting with 10.10.

SELECT ip_address 
FROM /network/device/interface/inet 
WHERE ip_address = ?10\.10\.\d+\.\d+?

Results: Depending on the database, the results look similar to this:

row
   ip_address 10.10.10.102
row
   ip_address 10.10.10.7
row
   ip_address 10.10.10.6 
   . . .

Example 3

Query: Find all IP addresses starting with something similar to 10.10.

SELECT ip_address 
FROM /network/device/interface/inet 
WHERE ip_address like ?10\.10\.\d+\.\d+?

Results: Depending on the database, the results look similar to this:

row
   ip_address 10.10.10.102
row
   ip_address 10.10.10.7
row
   ip_address 10.10.10.6 
   . . . 

 

Mac, iPad, and the Mac logo are trademarks of Apple, Inc. registered in the U.S. and other countries.