Sea Posted April 7, 2015 Share Posted April 7, 2015 (edited) Hi everybody I would like to have a regex for this file ; extension = bfb ; cost_per_hour = 0 ; g_code_prefix = 5E4669726D776172653A56312E30370A3B205B6D6D5D ; 206D6F64650A4732310A3B206162736F6C757465206D6F64650A4739 ; 300A ; fan_off = M107 ; z_speed_mm_per_s = 2.5 ; bed_offset_x_mm = -35I want an array like that '>. I succes to read each line with StringRegExp($Value, "(w+)(?: = )(.+)", 3) but it fail with multiline for g_code_prefix. Thanks you in advance Edited April 7, 2015 by Sea My project : [*]Structure parser for structure like C++ [*]Adobe auto saver [/list] Link to comment Share on other sites More sharing options...
jguinch Posted April 7, 2015 Share Posted April 7, 2015 One way : #Include <Array.au3> $sString = "extension = bfb" & @CRLF & _ "cost_per_hour = 0" & @CRLF & _ "g_code_prefix = 5E4669726D776172653A56312E30370A3B205B6D6D5D" & @CRLF & _ " 206D6F64650A4732310A3B206162736F6C757465206D6F64650A4739" & @CRLF & _ " 300A" & @CRLF & _ "fan_off = M107" & @CRLF & _ "z_speed_mm_per_s = 2.5" & @CRLF & _ "bed_offset_x_mm = -35" $aLines = StringRegExp( StringRegExpReplace($sString, "\R\h+", "") , "\N+", 3) _ArrayDisplay($aLines) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Sea Posted April 7, 2015 Author Share Posted April 7, 2015 (edited) Thanks but that's mean I need to edit my data before process them I don't really like this.And I don't have variable_name and value separated.But its a nice idea to add a StringRegExpReplace Edited April 7, 2015 by Sea My project : [*]Structure parser for structure like C++ [*]Adobe auto saver [/list] Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2015 Share Posted April 7, 2015 Another: #include <Array.au3> Local $sInput = _ "; extension = bfb" & @CRLF & _ "; cost_per_hour = 0" & @CRLF & _ "; g_code_prefix = 5E4669726D776172653A56312E30370A3B205B6D6D5D" & @CRLF & _ "; 206D6F64650A4732310A3B206162736F6C757465206D6F64650A4739" & @CRLF & _ "; 300A" & @CRLF & _ "; fan_off = M107" & @CRLF & _ "; z_speed_mm_per_s = 2.5" & @CRLF & _ "; bed_offset_x_mm = -35" & @CRLF ; this last line break optional $sInput = StringRegExpReplace($sInput, "\R;\s{2,}", "") ConsoleWrite($sInput & @LF) Local $aOutput = StringRegExp($sInput, "(?mx) ^ ; \s+ (\w+) \s+ = \s+ (.+) $", 3) If Not @error Then Local $aResult[UBound($aOutput) / 2][2] For $i = 0 To UBound($aResult) - 1 $aResult[$i][0] = $aOutput[2 * $i] $aResult[$i][1] = $aOutput[2 * $i + 1] Next _ArrayDisplay($aResult) Else ConsoleWrite("Non-conformal input." & @LF) EndIf This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jguinch Posted April 7, 2015 Share Posted April 7, 2015 (edited) ouups, sorry I didn't copy the ";" at the beginning of each line.... so, another attempt : #Include <Array.au3> $sContent = FileRead("file.txt") $aLines = StringRegExp( StringRegExpReplace($sContent, "(?:\R;\h{2,}|(?<=\n|^);\h+)", "") , "\N+", 3) _ArrayDisplay($aLines) Edited April 7, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2015 Share Posted April 7, 2015 And the leading '; ' ??? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Sea Posted April 7, 2015 Author Share Posted April 7, 2015 Amazing jchd thanks you a lot.Local $aOutput = StringRegExp($sInput, "(?mx) ^ ; \s+ (\w+) \s+ = \s+ (.+) $", 3)can you explain it plz? ^^'MX => multi lines so new line is determinated by a ; ?Why $ in the end? Thanks you its really what I need Btw thanks you too jguinch but I prefer the jchd output My project : [*]Structure parser for structure like C++ [*]Adobe auto saver [/list] Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2015 Share Posted April 7, 2015 This useful site explains it all thusly: /(?mx) ^ ; \s+ (\w+) \s+ = \s+ (.+) $/ (?mx) Match the remainder of the pattern with the following options: m modifier: multi-line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string) x modifier: extended. Spaces and text after a # in the pattern are ignored ^ assert position at start of a line ; matches the character ; literally \s+ match any white space character [\r\n\t\f ] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] 1st Capturing group (\w+) \w+ match any word character [a-zA-Z0-9_] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] \s+ match any white space character [\r\n\t\f ] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] = matches the character = literally \s+ match any white space character [\r\n\t\f ] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] 2nd Capturing group (.+) .+ matches any character (except newline) Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] $ assert position at end of a line SorryButImaNewbie and SupaNewb 2 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Sea Posted April 7, 2015 Author Share Posted April 7, 2015 I din't know this site. Thanks you a lot My project : [*]Structure parser for structure like C++ [*]Adobe auto saver [/list] Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 7, 2015 Share Posted April 7, 2015 That site looks usefull indeed! Link to comment Share on other sites More sharing options...
jchd Posted April 7, 2015 Share Posted April 7, 2015 Not only it offers several regex flavors (by default it is PCRE [ = AutoIt] compatible), but you can actually see a pattern at work step by step by hitting "regexp debugger". That's an excellent feature to learn how a pattern backtracks. Enter g in the option box (right to the pattern box) to mimic our StringRegExp option 3 (global match). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) 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