SOLVED

Escaping parenthesis in regular expression

%3CLINGO-SUB%20id%3D%22lingo-sub-1336735%22%20slang%3D%22en-US%22%3EEscaping%20parenthesis%20in%20regular%20expression%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1336735%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20everyone%2C%3CBR%20%2F%3EI%20am%20trying%20to%20extract%20text%20from%20the%20inside%20of%20parenthesis%20in%20a%20string.%3CBR%20%2F%3EFor%20example%3A%26nbsp%3B%3CBR%20%2F%3EFrom%20this%20string%20%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3EMicrosoft%20Office%20Excel%2F16.0.11929.20618%20(Windows%2F10.0%3B%20Desktop%20x64%3B%20en-IE%3B%20Desktop%20app%3B%20Dell%20Inc.%2FXPS%2013%209370)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EExtract%20only%3A%20(Windows%2F10.0%3B%20Desktop%20x64%3B%20en-IE%3B%20Desktop%20app%3B%20Dell%20Inc.%2FXPS%2013%209370)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3E%3CSPAN%3EI've%20tried%20this%20command%20in%20Log%20Analytics%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3CDIV%3E%3CSPAN%3E%7C%20%3C%2FSPAN%3E%3CSPAN%3Eextend%3C%2FSPAN%3E%3CSPAN%3E%20UserDevice%20%3D%20extract(%3C%2FSPAN%3E%3CSPAN%3E'%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3CSPAN%3E(.*%3C%2FSPAN%3E%3CSPAN%3E%5C%3C%2FSPAN%3E%3CSPAN%3E)'%3C%2FSPAN%3E%3CSPAN%3E%2C%200%3C%2FSPAN%3E%3CSPAN%3E%2C%20UserAgent%20)%3CBR%20%2F%3EAnd%20got%20a%20Syntax%20Error%3CBR%20%2F%3EIv'e%20uses%20%5C%20to%20escape%20special%20chracters%3A%20(%20and%26nbsp%3B%20)%3CBR%20%2F%3E%3CBR%20%2F%3EAnyone%20could%20assist%3F%3C%2FSPAN%3E%3CBR%20%2F%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1336735%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Log%20Analytics%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EQuery%20Language%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1339059%22%20slang%3D%22en-US%22%3ERe%3A%20Escaping%20parenthesis%20in%20regular%20expression%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1339059%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F579140%22%20target%3D%22_blank%22%3E%40DavidSho%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%5C%20is%20a%20special%20character%20so%20you%20need%20two%20of%20them%20%22%5C%5C%22%2C%20this%20wont%20error%20now%2C%20but%20gets%20all%20between%20the%20%22(%22%20and%20%22)%22.%26nbsp%3B%20%26nbsp%3Be.g.%20%22%3CSPAN%3E(Windows%2F10.0%3B%20Desktop%20x64%3B%20en-IE%3B%20Desktop%20app%3B%20Dell%20Inc.%2FXPS%2013%209370)%3C%2FSPAN%3E%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3Eprint%20t%20%3D%20%22Microsoft%20Office%20Excel%2F16.0.11929.20618%20(Windows%2F10.0%3B%20Desktop%20x64%3B%20en-IE%3B%20Desktop%20app%3B%20Dell%20Inc.%2FXPS%2013%209370)%22%0A%7C%20extend%20UserDevice%20%3D%20extract('%5C%5C(.*%5C%5C)'%2C%200%2C%20t%20)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1347373%22%20slang%3D%22en-US%22%3ERe%3A%20Escaping%20parenthesis%20in%20regular%20expression%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1347373%22%20slang%3D%22en-US%22%3ETHANK%20YOU%20!!!%3C%2FLINGO-BODY%3E
Highlighted
Occasional 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
Highlighted
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 )

 

 

Highlighted
THANK YOU !!!