RegEx 108-Return your match in AutoHotkey Regular Expressions match object

AutoHotkey Regular Expressions match objectNeed to get additional information about your RegExMatch?  Why not return a AutoHotkey Regular Expressions match object?  Having your data returned in an object allows for some great information like: Length, location, name of subpattern, etc.  With AHK  you can use the O) option to store the matches into an AutoHotkey object.  The below video walks through how to do it and gives you a clear example how to access it once it is created.

Create and access an AutoHotkey Regular Expressions match object

Here is the code demonstrated in the videoAutoHotkey Merchandise-White Stress ball

Browser_Forward::Reload
Browser_Back::
str:="Hello, world   how are you doing"  ;define String
RegExMatch(str,"O)(?P<Word>\w+)(?P<delim>[\s|?|.|,]+)",obj)

MsgBox % "     value: " obj.Word "`r"
 	   . "  value:  " obj.Value["Word"]  "`r"
	   . "position: " obj.Pos["Word"]  "`r"
	   . "  Length: " obj.len["Word"]  "`r"
	   . "    Name: " obj.Name["Word"]  "`r"
	   . "  Count:  " obj.Count()  "`r"

MsgBox % "     value: " obj.delim "`r"
 	   . "  value:  " obj.Value["Delim"]  "`r"
	   . "position: " obj.Pos["delim"]  "`r"
	   . "  Length: " obj.len["delim"]  "`r"
	   . "    Name: " obj.Name["delim"]  "`r"
	   . "  Count:  " obj.Count()  "`r"

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.