Jump to content
seadoggie01

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.

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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)

Share this post


Link to post
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

 

Share this post


Link to post
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)

Share this post


Link to post
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.

Share this post


Link to post
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)

Share this post


Link to post
Share on other sites
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  :D

Share this post


Link to post
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)

Share this post


Link to post
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

  • Similar Content

    • By genius257
      Inspired by PHP's preg_split.
      Split string by a regular expression.
      Also supports the same flags as the PHP equivalent.
      v1.0.1
       
      Example:
      #include "StringRegExpSplit.au3" StringRegExpSplit('splitCamelCaseWords', '(?<=\w)(?=[A-Z])') ; ['split', 'Camel', 'Case', 'Words']  
    • By RAMzor
      Hi guys I need your help.
      I have string like this : "TDM111A5,      RCT222Y5/ 7  ; FDT444E4 /8 , ABC222R5"
      I need find a coma or semicolon and delete white spaces before and after them
      The output should be a string and/or array 
      String : "TDM111A5,RCT222Y5/ 7;FDT444E4 /8,ABC222R5"
      Array:
      TDM111A5
      RCT222Y5/ 7
      FDT444E4 /8
      ABC222R5
    • By BlueBandana
      Is there a way to output the regex matches into a file?
      I have a script to compare two files and check for regex matches.
      I want to output the matching regex of 'testexample.txt' to another file.
      #include <MsgBoxConstants.au3> #include <Array.au3> $Read = FileReadToArray("C:\Users\admin\Documents\testexample.txt") $Dictionary = FileReadToArray("C:\Users\admin\Documents\example.txt") For $p = 0 To UBound($Dictionary) - 1 Step 1 $pattern = $Dictionary[$p] For $i = 0 To UBound($Read) - 1 Step 1 $regex = $Read[$i] If StringRegExp($regex, $pattern, 0) Then MsgBox(0, "ResultsPass", "The string is in the file, highlighted strings: " ) Else MsgBox(0, "ResultsFail", "The string isn't in the file.") EndIf Next Next  
    • By junichironakashima
      Im creating a code that will work in this sequence:
      1. Copy the text (question) in one atea of the screen
      2. Catch the 2 strings (number)
      3. Multiply the 2 strings ( $1*$2)
      4. Click the next area to put the answer
      5. Paste the answer
       
      This is my code
       
      MouseClick($MOUSE_CLICK_LEFT, 479, 802, 3, 1) ;Clicking all of the text
      Send("^c") 
      $x = StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2")
      MouseClick($MOUSE_CLICK_LEFT, 480, 844, 1, 1)
      ClipPut($x)
      Send("^v")
       
      However the output is this
      $1*$2
       
      How can I make it solve itself? Because I tried this code:
      MouseClick($MOUSE_CLICK_LEFT, 479, 802, 3, 1) ;Clicking all of the text
      Send("^c")
      MouseClick($MOUSE_CLICK_LEFT, 480, 844, 1, 1) $x = Execute(StringRegExpReplace(ClipGet(), 'What is (\d*) x (\d*) \?$', "$1*$2"))
      ClipPut($x)
      Send("^v")
      Output is just blank text

    • By mLipok
      In April 5, 2013 I ask @Lazycat 
      he answer:
      Then I change this tool a little.
      Now I back to this and make bigger changed.
      Here is new version.
      Update History: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2018/11/07 v3.0 * Changed: AU3Check compilant - mLipok * Changed: almost all Variables renamed - mLipok * Added: "Delete RegExp Results" - mLipok * Added: support for dual monitor - mLipok * Added: "full screen mode" - mLipok = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2018/11/08 v3.1 * Added: colors for each Edit control - used GUICtrlSetBkColor() - mLipok * Added: FullScreen option (Checkbox + INI + Remarks in Tip) - mLipok * Added: _IsChecked() - mLipok * Changed: WinMove() - change size of window using: WindowWidth and WindowHeight - mLipok = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2018/11/13 v3.2 * Added: If $bFullScreen Then GUICtrlSetFont() - mLipok * Added: WM_COMMAND , $EN_CHANGE - prevent CPU overheat - mLipok = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 2018/11/29 v3.3 * Changed: $_g_idCheckbox_Clear - also clear $_g_idEdit_Result - mLipok * Changed: ClearResult If GUICtrlRead($_g_idEdit_MatchText) = '' Or GUICtrlRead($_g_idEdit_MatchText) = '' - mLipok * Fixed: prevention CPU overheat - If $iGuiMsg <> 0 Then $_g_bWasAChange = True - any GUI change will fire RegExp result refresh - mLipok * Fixed: Top possition of $_g_idLabel_Dummy control - mLipok * Added: support for TabSwitch - CTRL+TAB and CTRL+SHIFT+TAB - mLipok = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =  
×
×
  • Create New...