Jump to content

RegExp Multiline Comments


Recommended Posts

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 functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

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

 

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 here
RegExp tutorial: enough to get started
PCRE 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

Wow. Thank you! I think I see what my problem was... kind of :D 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 functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

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)

:P

Link to comment
Share on other sites

@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 here
RegExp tutorial: enough to get started
PCRE 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

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

 

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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

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 :D

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 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 functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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

:robot:

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 here
RegExp tutorial: enough to get started
PCRE 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...