HurleyShanabarger 18 Posted January 24 Share Posted January 24 Hello, I am struggeling again with a simple expression. I want to search for ccc and get aaa as return (for fff i expect ddd and so on). aaa := bbb OR ccc; ddd := eee OR fff; ggg := hhh OR iii; here is my code: #Region Includes #include <Array.au3> #include <Date.au3> #include <File.au3> #include <Misc.au3> #include <String.au3> #EndRegion Includes #Region Main _Main() Func _Main() Local $sgData $sgData &= " aaa := bbb OR" & @CRLF $sgData &= " ccc;" & @CRLF $sgData &= " ddd := eee OR" & @CRLF $sgData &= " fff;" & @CRLF $sgData &= " ggg := hhh OR" & @CRLF $sgData &= " iii;" & @CRLF Local $arMatch = StringRegExp($sgData, "(?ms)^.+?iii\b", 3) _ArrayDisplay($arMatch) EndFunc ;==>_Main I am not getting the match I am expecting. Thanks for your help! Link to post Share on other sites
Malkey 243 Posted Wednesday at 07:41 AM Share Posted Wednesday at 07:41 AM Try this. #include <Debug.au3> _Main() Func _Main() Local $sgData $sgData &= " aaa := bbb OR" & @CRLF $sgData &= " ccc;" & @CRLF $sgData &= " ddd := eee OR" & @CRLF $sgData &= " fff;" & @CRLF $sgData &= " ggg := hhh OR" & @CRLF $sgData &= " iii;" & @CRLF $sgData &= " jjj := kkk OR" & @CRLF $sgData &= " ccc;" & @CRLF $sSearch = "ccc" ; "fff" ; "iii" ; Local $sMatch = StringRegExpReplace($sgData, "\s+([a-z]{3}).+\s+" & $sSearch & ";(\R)|\R*.*", "\1\2") ConsoleWrite(StringStripWS($sMatch, 2) & @CRLF) ; $STR_STRIPTRAILING (2) = strip trailing white space ; Or Local $aMatch = StringRegExp($sgData, "([a-z]{3}).+\s+" & $sSearch, 3) _DebugArrayDisplay($aMatch) EndFunc ;==>_Main Link to post Share on other sites
mikell 1,140 Posted Wednesday at 10:48 AM Share Posted Wednesday at 10:48 AM (edited) My try... (for the fun) #include <Array.au3> Local $sgData $sgData &= "aaa := bbb OR" & @CRLF $sgData &= " ccc;" & @CRLF $sgData &= "dddd := eee OR" & @CRLF $sgData &= " fff;" & @CRLF $sgData &= " ggggg := hhh OR" & @CRLF $sgData &= " iii;" & @CRLF $search = "fff" ;"iii" ;"ccc" ; $res = StringRegExp($sgData, '(\S+).+\s+' & $search, 3) _ArrayDisplay($res) $res = StringRegExpReplace($sgData, '(?ms).*(?=(?:^|\h)(\H+)\h:=.+?' & $search & ').*', "$1") Msgbox(0,"", $res) Edited Wednesday at 11:04 AM by mikell added SRER Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now