Forum Discussion
DavidSho
Apr 24, 2020Copper Contributor
Escaping parenthesis in regular expression
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?
And got a Syntax Error
Iv'e usesd \ to escape special chracters: ( and )
Anyone could assist?
\ 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 )
2 Replies
- CliveWatsonSilver Contributor
\ 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 )
- DavidShoCopper ContributorTHANK YOU !!!