SOLVED

Escaping parenthesis in regular expression

Copper Contributor

Hello everyone,
I am trying to extract text from the inside of parenthesis in a string.
For example: 
From this string :

Microsoft Office Excel/16.0.11929.20618 (Windows/10.0; Desktop x64; en-IE; Desktop app; Dell Inc./XPS 13 9370)
 
Extract only: (Windows/10.0; Desktop x64; en-IE; Desktop app; Dell Inc./XPS 13 9370)
 
I've tried this command in Log Analytics
| extend UserDevice = extract('\(.*\)', 0, UserAgent )
And got a Syntax Error
Iv'e usesd \ to escape special chracters: ( and  )

Anyone could assist?
2 Replies
best response confirmed by CliveWatson (Microsoft)
Solution

@DavidSho 

 

\ is a special character so you need two of them "\\", this wont error now, but gets all between the "(" and ")".   e.g. "(Windows/10.0; Desktop x64; en-IE; Desktop app; Dell Inc./XPS 13 9370)"

 

print t = "Microsoft Office Excel/16.0.11929.20618 (Windows/10.0; Desktop x64; en-IE; Desktop app; Dell Inc./XPS 13 9370)"
| extend UserDevice = extract('\\(.*\\)', 0, t )

 

 

THANK YOU !!!
1 best response

Accepted Solutions
best response confirmed by CliveWatson (Microsoft)
Solution

@DavidSho 

 

\ is a special character so you need two of them "\\", this wont error now, but gets all between the "(" and ")".   e.g. "(Windows/10.0; Desktop x64; en-IE; Desktop app; Dell Inc./XPS 13 9370)"

 

print t = "Microsoft Office Excel/16.0.11929.20618 (Windows/10.0; Desktop x64; en-IE; Desktop app; Dell Inc./XPS 13 9370)"
| extend UserDevice = extract('\\(.*\\)', 0, t )

 

 

View solution in original post