HurleyShanabarger Posted January 24, 2023 Share Posted January 24, 2023 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 comment Share on other sites More sharing options...
Malkey Posted January 25, 2023 Share Posted January 25, 2023 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 comment Share on other sites More sharing options...
mikell Posted January 25, 2023 Share Posted January 25, 2023 (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 January 25, 2023 by mikell added SRER Link to comment Share on other sites More sharing options...
HurleyShanabarger Posted February 6, 2023 Author Share Posted February 6, 2023 Thank you ver much for the suggestions. I adjusted it slightly to $res = StringRegExp($sgData, '(?m)^ +(\S+).+\s+\Q' & $search & '\E', 3) to have faster matching, as it took quite some time for big data. Link to comment Share on other sites More sharing options...
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