Allow2010 Posted May 11, 2013 Share Posted May 11, 2013 (edited) i am trying to parse some textinfo and it just seems not to work. here you can see what i am trying to do http://regexr.com?34r61 i want to find the state (active or not) for all ten devices. the regexp (?ms)["tam:settings/TAM/list(Active,Name,Display,MSNBitmap)"] = {.*[4] = {s*["Active"] = "([10])", seems to work and i can get the needed result by changing the numer (in bold). I tried this in autoit with $tam=4 $state = StringRegExp($text, '["tam:settings/TAM/list(Active,Name,Display,MSNBitmap)"] = {s*[' & $tam & '] = {s*["Active"] = "([10])",', 1) but i never get a result... can anyone please help me:-) Edited May 11, 2013 by Allow2010 Link to comment Share on other sites More sharing options...
guinness Posted May 11, 2013 Share Posted May 11, 2013 (edited) Where is that json syntax from? Also look at the last parameter, change from 1 to 3. Edited May 11, 2013 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mikell Posted May 11, 2013 Share Posted May 11, 2013 (edited) Try this #include <Array.au3> $text = FileRead("1.txt") $state = StringRegExp($text, '(?s)Active"\] = "(\d)"', 3) _ArrayDisplay($state) Edit Or this #include <Array.au3> $text = FileRead("1.txt") $state = StringRegExp($text, '(?s)Active"\] = "(\d)"', 3) Dim $array[UBound($state)+1][2] = [["device", "status"]] For $i = 1 to UBound($state) $array[$i][0] = $i $array[$i][1] = $state[$i-1] Next _ArrayDisplay($array) Edited May 11, 2013 by mikell Link to comment Share on other sites More sharing options...
Allow2010 Posted May 11, 2013 Author Share Posted May 11, 2013 Where is that json syntax from? Also look at the last parameter, change from 1 to 3. i am not sure what you mean by json syntax... Link to comment Share on other sites More sharing options...
Allow2010 Posted May 11, 2013 Author Share Posted May 11, 2013 Try this thanks, i will try and report back...but (as the file holds some more text) it might be a bit too simple and may match something that looks similar..thats why i decided to match tam:settings/TAM/list(Active,Name,Display,MSNBitmap)"] first... Link to comment Share on other sites More sharing options...
mikell Posted May 11, 2013 Share Posted May 11, 2013 Frequently, more complicated the expression is, more errors may occur I based this regex on the text you provided with your link, but if you have to manage something different the sre must obviously be adapted Link to comment Share on other sites More sharing options...
Jury Posted May 12, 2013 Share Posted May 12, 2013 (edited) Whatever but don't forget the powerful; (?=[d+]) This asserts that this: [d+]) can be matched, then continues by starting at this position and so on until end of file Z in my script. #include <Array.au3> $text = FileRead(@MyDocumentsDir & "\test.txt") $state = StringRegExp($text, '(?-s)\[\d+\].*?\r?\n.*?\["Active"\]\s*=\s*"(\d+)"(?s).*?(?=\[\d+\]|\Z)', 3) Dim $array[UBound($state)+1][2] = [["device", "status"]] For $i = 1 to UBound($state) $array[$i][0] = $i $array[$i][1] = $state[$i-1] Next _ArrayDisplay($array) Edited May 12, 2013 by Jury kylomas 1 Link to comment Share on other sites More sharing options...
Allow2010 Posted May 13, 2013 Author Share Posted May 13, 2013 (edited) Whatever but don't forget the powerful; (?=[d+]) This asserts that this: [d+]) can be matched, then continues by starting at this position and so on until end of file Z in my script. #include <Array.au3> $text = FileRead(@MyDocumentsDir & "\test.txt") $state = StringRegExp($text, '(?-s)\[\d+\].*?\r?\n.*?\["Active"\]\s*=\s*"(\d+)"(?s).*?(?=\[\d+\]|\Z)', 3) Dim $array[UBound($state)+1][2] = [["device", "status"]] For $i = 1 to UBound($state) $array[$i][0] = $i $array[$i][1] = $state[$i-1] Next _ArrayDisplay($array) Well, thank you...but i have to take a very close look at this to understand it...will reply when i understand :-) Edited May 13, 2013 by Allow2010 Link to comment Share on other sites More sharing options...
Allow2010 Posted May 13, 2013 Author Share Posted May 13, 2013 (edited) Meanwhile i have another regexp problem that gives me a headache: <textarea id="uiDnsRebind" name="dns_rebind_list" cols="30" rows="5">Line1 Line2 Line3 morelines</textarea> i want the text between <textarea id="uiDnsRebind" name="dns_rebind_list" cols="30" rows="5"> and </textarea> and i can sucessfully get it with $matches = StringRegExp($result, '(?ms)<textarea id="uiDnsRebind" name="dns_rebind_list" cols="30" rows="5">(.*?)</textarea>', 1) but after that all the linefeeds are converted to the text "lf". Not sure why that is... Can anyone tell me how i can get this as a result: "Line1%0D%0ALine2%0D%0ALine3%0D%0Amorelines%0D%0A" I am banging my head now for over an hour:-( Edited May 13, 2013 by Allow2010 Link to comment Share on other sites More sharing options...
mikell Posted May 13, 2013 Share Posted May 13, 2013 I'm not sure of the result you exactly expect but please try this $txt = '<textarea id="uiDnsRebind" name="dns_rebind_list" cols="30" rows="5">Line1' & @crlf & _ 'Line2' & @crlf & _ 'Line3' & @crlf & _ 'morelines' & @crlf & _ '</textarea>' $res = StringRegExp($txt, '(?s)<textarea.+?>(.*?)<', 3) msgbox(0, "", $res[0]) $res2 = StringReplace($res[0], @crlf, '%0D%0A') msgbox(0, "", $res2) Link to comment Share on other sites More sharing options...
Allow2010 Posted May 14, 2013 Author Share Posted May 14, 2013 Thank Your, it works fine...only problem i had was that for some reasons the text i am parsing used @LF instead of @CRLF. Once i found it all worked out... Thanks again to everyone for the help... Link to comment Share on other sites More sharing options...
guinness Posted May 14, 2013 Share Posted May 14, 2013 Rule of thumb >> Windows >> rn or @CRLF for line endings. It just stops problems like this happening. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mikell Posted May 14, 2013 Share Posted May 14, 2013 ...for some reasons the text i am parsing used @LF instead of @CRLF. Once i found it all worked out... You can solve this with regexp $txt = '<textarea id="uiDnsRebind" name="dns_rebind_list" cols="30" rows="5">Line1' & @crlf & _ 'Line2' & @lf & _ 'Line3' & @lf & _ 'morelines' & @crlf & _ '</textarea>' ;msgbox(0, "", $txt ) $res = StringRegExp($txt, '(?s)<textarea.+?>(.*?)<', 3) ;msgbox(0, "", $res[0]) $res2 = StringRegExpReplace($res[0], @crlf & '|' & @lf, '%0D%0A') ;<<<<<< msgbox(0, "", $res2) Link to comment Share on other sites More sharing options...
kylomas Posted May 14, 2013 Share Posted May 14, 2013 F.Y.I. M23 came up with this slick assed SRE to normalize EOL's ; By Melba23, convert @CR & @LF to @CRLF. Using lookarounds, very clever! $sReturn = StringRegExpReplace($sReturn, '((?<!\x0d)\x0a|\x0d(?!\x0a))', @CRLF) kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
guinness Posted May 14, 2013 Share Posted May 14, 2013 I need to ask why Melba23 why he opted for the hex values instead of r and n? ; By Melba23, convert @CR & @LF to @CRLF. Using lookarounds, very clever! $sReturn = StringRegExpReplace($sReturn, '((?<!\r)\n|\r(?!\n)', @CRLF) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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