Jump to content

StringRegExp Capture


Deye
 Share

Go to solution Solved by mikell,

Recommended Posts

$sPattern first formed by @mikell

Now I need it to work just the same but also to skip lines that contain " = GUICtrlCreateDummy()"

#include <Array.au3>

$sPattern = '(?ims)^\h*(?|(?:local|Global)\h+(\N+)|((?|\$|GUI[cs])\N+))(?=.*GUISetState)'

_Read("GUICtrlCreateDummy.au3")
_Read("_WinAPI_CallWindowProc.au3")
_Read("GUICtrlCreateContextMenu[2].au3")

Func _Read($file)
    Local $sPath = @ProgramFilesDir & "\AutoIt3\Examples\Helpfile\"
    _ArrayDisplay(StringRegExp(FileRead($sPath & $file), $sPattern, 3))
EndFunc

TIA

Edit: was a bit impatient posting this:

so i just added this to the pattern and it works  : .*[= ]\QGUICtrlCreateDummy()\E.*\R?(*SKIP)(?!)|

Edited by Deye
Link to comment
Share on other sites

  • Solution

Honestly I can't remember this thing :)

In such cases I personally use a small func to first remove empty lines and lines containing the unwanted string - or several unwanted strings, in this case write them in the $filter param with a separator (here I used a semicolon)

#include <Array.au3>

$sPattern = '(?ims)^\h*(?|(?:local|Global)\h+(\N+)|((?|\$|GUI[cs])\N+))(?=.*GUISetState)'

_Read("GUICtrlCreateDummy.au3")
_Read("_WinAPI_CallWindowProc.au3")
_Read("GUICtrlCreateContextMenu[2].au3")

Func _Read($file)
    Local $sPath = @ProgramFilesDir & "\AutoIt3\Examples\Helpfile\"
    $txt = _clean(FileRead($sPath & $file), "GUICtrlCreateDummy()")
    _ArrayDisplay(StringRegExp($txt, $sPattern, 3))
EndFunc

Func _clean($txt, $filter, $separator = ";")
   $filter = "\Q" & StringReplace($filter, $separator, "\E|\Q") & "\E"
   Return StringRegExpReplace($txt, '(?m)^(\s*|.*(?:' & $filter & ').*)$\R?', "")
EndFunc

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...