seadoggie01 Posted November 19, 2019 Posted November 19, 2019 I'm trying to capture everything after a "#ToDo" in my scripts. I got that like this: (?i)[^\v]*#todo(.*) But then I thought it would be nice to use underscores to continue the ToDo... kind of like this: #ToDo: This is a really long explanation about something _ # that is very in-depth and needs to take up a lot of _ # space in a ToDo comment Global $variables = "Bad" I can't seem to capture everything... and maybe I'm trying to do too much with Regex... I keep trying variations of this: Condensed Version: (?im)[^\v]*#todo(?:([^\v]*)_\s*)*#([^\v]*) Expanded with comments (?ixm)(?# Ignore case, ignore newlines in Regex, use multiline option)# [^\v]*(?# Match leading space/s)# \#todo(?# Match the #todo)# (?:([^\v]*)_\s*)*(?# Match lines ending with _)# \#([^\v]*)(?# Last line only, no _'s)# I never seem to be able to build an array well with Regex... I saw something once about not being able to capture repeated patterns, and I think that's my issue All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
jchd Posted November 19, 2019 Posted November 19, 2019 Would that fit? Local $s = "#include <Inet.au3>" & @CRLF & _ "#ToDo: This is a really long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of _" & @CRLF & _ "# space in a ToDo comment" & @CRLF & _ 'Global $variables = "Bad"' & @CRLF & _ "#ToDo: This is another long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of space in a ToDo comment" & @CRLF & _ "#include <IE.au3>" Local $aToDo = StringRegExp($s, "(?im)^\h*(#todo:(?:.* +_\R)*(?:.* *\R))", 3) For $c In $aToDo ConsoleWrite($c & @LF) Next seadoggie01 1 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)
seadoggie01 Posted November 19, 2019 Author Posted November 19, 2019 Wow. Thank you! I think I see what my problem was... kind of I was trying to capture just the comment, instead of everything after the #ToDo until the end. I like that you put the colon in after #ToDo, it looks better. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
mikell Posted November 19, 2019 Posted November 19, 2019 Sometimes using a first step just before the main regex can make the thingy sooo easy... Local $s = "#include <Inet.au3>" & @CRLF & _ "#ToDo: This is a really long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of _" & @CRLF & _ "# space in a ToDo comment" & @CRLF & _ 'Global $variables = "Bad"' & @CRLF & _ "#ToDo: This is another long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of space in a ToDo comment" & @CRLF & _ "#include <IE.au3>" $r1 = StringRegExpReplace($s, '\h*_\h*\R#\h*', " ") Msgbox(0,"", $r1) seadoggie01 1
jchd Posted November 20, 2019 Posted November 20, 2019 @mikell we don't seem to have understood the same request 🙄 I know I'm getting picky, but : Local $s = "#include <Inet.au3>" & @CRLF & _ "#blah_" & @CRLF & _ "#blah_" & @CRLF & _ "# ..._" & @CRLF & _ "# blah _" & @CRLF & _ "#ToDo: This is a really long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of _" & @CRLF & _ "# space in a ToDo comment" & @CRLF & _ "#AutoIt3Wrapper_Res_Comment=Blah blah _" & @CRLF & _ "#include <WinAPI.au3>" & @CRLF & _ 'Global $variables = "Bad"' & @CRLF & _ "#ToDo: This is another long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of space" & @CRLF & _ "#include <IE.au3>" & @CRLF & _ "#ToDo: This is the last long explanation about something _" & @CRLF & _ "# that is very boring" $r1 = StringRegExpReplace($s, '\h*_\h*\R#\h*', " ") Msgbox(0,"", $r1) 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)
mikell Posted November 20, 2019 Posted November 20, 2019 5 hours ago, jchd said: we don't seem to have understood the same request We had... maybe. Isn't the content of the ToDo comments to be grabbed ? I only meant that doing this in 2 steps makes the job much easier, and the 2nd step was so obvious that I didn't write it Local $s = "#include <Inet.au3>" & @CRLF & _ "#blah_" & @CRLF & _ "#blah_" & @CRLF & _ "# ..._" & @CRLF & _ "# blah _" & @CRLF & _ "#ToDo: This is a really long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of _" & @CRLF & _ "# space in a ToDo comment" & @CRLF & _ "#AutoIt3Wrapper_Res_Comment=Blah blah _" & @CRLF & _ "#include <WinAPI.au3>" & @CRLF & _ 'Global $variables = "Bad"' & @CRLF & _ "#ToDo: This is another long explanation about something _" & @CRLF & _ "# that is very in-depth and needs to take up a lot of space" & @CRLF & _ "#include <IE.au3>" & @CRLF & _ "#ToDo: This is the last long explanation about something _" & @CRLF & _ "# that is very boring" $r1 = StringRegExpReplace($s, '\h*_\h*\R#\h*', " ") ;Msgbox(0,"", $r1) $r2 = StringRegExp($r1, 'ToDo: (.+)', 3) For $i = 0 to UBound($r2)-1 Msgbox(0,"ToDo " & $i+1, $r2[$i]) Next
jchd Posted November 20, 2019 Posted November 20, 2019 Yeah but why use one hammer and one wrench for only one screw? 🛠️ 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)
seadoggie01 Posted November 20, 2019 Author Posted November 20, 2019 (edited) 16 hours ago, mikell said: Sometimes using a first step just before the main regex can make the thingy sooo easy... Yup, that makes it much easier! And I can change it later without re-learning everything 5 hours ago, jchd said: we don't seem to have understood the same request He just did the first step in the process, his point was not to do everything at once and simplify life Edit: Oops, ninja-ed Edited November 20, 2019 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
jchd Posted November 20, 2019 Posted November 20, 2019 Every point of view has advantages. 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)
mikell Posted November 20, 2019 Posted November 20, 2019 7 hours ago, jchd said: Every point of view has advantages. I agree (though it depends on the wanted result) And I didn't use hammer + wrench, I used oil + wrench, it's not exactly the same
jchd Posted November 20, 2019 Posted November 20, 2019 mikell 1 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)
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