ComputorEdge E-Books

ComputorEdge

Table of Contents      Regular Expressions Index

AutoHotkey RegEx

A Beginner's Guide to Using Regular Expressions in AutoHotkey


"Exploring the Mysteries of RegEx"
 
AutoHotkey is a powerful scripting language for Windows XP, Windows Vista, Windows 7, Windows 8, and Windows 10. If you don't already use AutoHotkey with your Windows computers, then you should start. The language is simple, yet powerful. Best of all, it's free to use.

This Beginner's Guide to Using Regular Expressions in AutoHotkey is not a beginning level AutoHotkey book, but an introduction to using Regular Expressions in AutoHotkey (or most other programming languages). To get the most from this book you should already have a basic understanding of AutoHotkey (or another programming language). Regular Expressions (RegEx) are a powerful way to search and alter documents without the limitations of most of the standard matching functions. At first, the use of RegEx can be confusing and mysterious. This book clears up the confusion with easy analogies for understanding how RegEx works and examples of practical AutoHotkey applications. Regular Expressions in AutoHotkey will take you to the next level in AutoHotkey scripting while adding more flexibility and power to your Windows apps.

Regular Expressions (commonly called RegEx or RegExp) in AutoHotkey is not a beginning level script writing topic and there certainly is nothing regular about Regular Expressions. Jack spent a good bit of time exploring the various programming tools and has developed a healthy respect for RegEx flexibility and power. Many (including Jack) have avoided using RegEx due to its enigmatic code which at times appears almost incomprehensible. It's not like normal program code with If-Then-Else statements and Loops. Writing a RegEx is not merely a matter of following a logical sequence. It often requires a non-linear look at the problem. Jack's found that what helps him most is the analogy he envisions in his brain pan. That image gives a basis for what a RegEx is trying to do. ("Try" is a good word when describing RegExs. Whereas the usual programming either works or doesn't work, RegEx "tries" to find pattern matches. If none are found, it moves on.)

The chapters in this book are grouped by their place in developing a deeper understanding of Regular Expressions while emphasizing the practical application of RegExMatch() and RegExReplace()—the two primary AutoHotkey Regular Expressions functions.

The first three chapters are the most important for getting a quick start on how to view and understand Regular Expressions and the AutoHotkey RegEx functions, while the remaining chapters can be studied in almost any order as they each demonstrate one or more practical RegEx applications—i.e. finding double words in text (Chapter Five); fixing mistyped word contractions (Chapter Six); swapping two word in any text editing (Chapter Seven); extracting IP addresses from text, then extracting the geographic location of each from the Web (Chapter Eight); stripping HTML tags from source code leaving only pure text (Chapter Nine); extracting links from a Web page and saving them to a text file (Chapter Ten); and validating e-mail addresses (Chapter Eleven). The final two chapters address slightly more advanced, but important topics, look-ahead and look-behind assertions, plus RegEx Properties \p{xx}.

If you're a novice script writer, you may be better served by starting with a beginning book or tutorial. If you're a more experienced programmer, then "Regular Expressions in AutoHotkey" may act as a reference for how and when to use them in your AutoHotkey applications.


This Beginner's Guide to Using Regular Expressions in AutoHotkey is not a beginning level AutoHotkey book, but an introduction to using Regular Expressions in AutoHotkey (or most other programming languages). To get the most from this book you should already have a basic understanding of AutoHotkey (or another programming language). Regular Expressions (RegEx) are a powerful way to search and alter documents without the limitations of most of the standard matching functions. At first, the use of RegEx can be confusing and mysterious. This book clears up the confusion with easy analogies for understanding how RegEx works and examples of practical AutoHotkey applications. "Regular Expressions in AutoHotkey" will take you to the next level in AutoHotkey scripting while adding more flexibility and power to your Windows apps.
(This book is also available at Amazon.com)

Table of Contents to A Beginner's Guide to Using Regular Expressions in AutoHotkey

Foreword

"There is nothing regular about Regular Expressions."

This is not a beginning AutoHotkey book, but a journey into RegEx for AutoHotkey users.

Chapter One: Understanding the Mysteries of Regular Expressions (RegEx) in AutoHotkey

"To Understand How a RegEx Works, It Helps to See Trains Running Down a Track"

Many AutoHotkey script writers don't use Regular Expressions because they seem too mysterious and confusing. All they really need is a little understanding.

Chapter Two: An Introduction to Easy Regular Expressions (RegEx) in AutoHotkey

"A quick guide to understanding how Regular Expressions (RegEx) work in AutoHotkey."

Regular Expressions (RegEx) are notorious for driving people insane, but taken a little at a time they can be simple.

Chapter Three: AutoHotkey RegExMatch() Versus RegExReplace()

"AutoHotkey Regular Expression functions (RegEx) can make complex text extractions and replacements easy."

Although RegEx in AutoHotkey can be confusing, it's worth the time to learn how to use the functions RegExMatch() and RegExReplace() for the power they deliver to your scripts.

Chapter Four: Simplified Regular Expressions in AutoHotkey

"More Regular Expression Tricks with Numbers for AutoHotkey Validation"

This time there are more simple examples of how to use RegEx functions to manipulate data in AutoHotkey.

Chapter Five: Eliminating Double Words with RegEx

"How to Use AutoHotkey RegEx to Eliminate Duplicate Words—RegExReplace()"

Digging deeper into AutoHotkey RegEx with an expression that will find and remove double words in any text, anywhere.

Chapter Six: Fixing Contractions with RegEx

"RegEx can fix multiple errors in contractions such as isn't and won't—RegExReplace()"

Another practical example of a Regular Expression in AutoHotkey with word contractions.

Chapter Seven:A Simple Beginner's Trick for Swapping Letters and Words

"An AutoHotkey Technique for Swapping the Order of Words—RegExReplace()"

Jack shows some easy AutoHotkey techniques for swapping errant letters or words, then step-by-step builds a Regular Expression (RegEx) for doing the same thing and more—with only one line of code.

Chapter Eight: A Simple Way to Find Out Where in the World That IP Address Is Located

"Find IP Addresses in E-mail, Documents and Web Pages, Then Automatically Locate Them!—RegExMatch()"

Have you ever wanted to know where that Spam is coming from or the geographic location of an IP address? This short AutoHotkey script extracts IP addresses from any selected text and downloads its world location from the Web.

Chapter Nine: Stripping Out HTML Tags

"How to extract and save the text from a web page—RegExReplace()"

Learn how to strip HTML tags from Web pages with AutoHotkey RegEx.

Chapter Ten: An App for Extracting Web Links from Web Pages

"Web Link Extractor AutoHotkey Scripts—RegExMatch()"

Need to save Web links from Web pages? Here are two AutoHotkey scripts which do the job.

Chapter Eleven: Verifying E-mail Addresses with AutoHotkey

"How e-mail address checking works with AutoHotkey RegEx."

There are plenty free Regular Expression (RegEx) examples on the Web. The problem is that they do not all work as advertised.

Chapter Twelve: Look-Ahead and Look-Behind RegEx Mysteries

"Look in front of and behind the Haystack for RegEx signposts to create a match."

A look at the confusing world of look-ahead and look-behind assertions in AutoHotkey RegEx. See how they can extend the power of Regular Expressions.

Chapter Thirteen: Using RegEx Property Symbols

"RegEx Properties \p{xx} extend the flexibility of Regular Expressions."

Use properties (\p{xx}) in AutoHotkey RegEx to correct punctuation, change currency symbols, and remove sets of brackets and parentheses.

Index to A Beginner's Guide to Using Regular Expressions in AutoHotkey

$ end or terminating anchor; Chapter Four; Chapter Eleven
(…) order of evaluation, capture special features, or change options; Chapter Eleven

* Match preceding 0 or more times; Chapter Eleven
^ Do not match inside a range [^…]; Chapter Four
^ Front end or beginning anchor; Chapter Four; Chapter Eleven
^ Circumflex; Chapter Four
^\d. Exclude all digits and decimal points; Chapter Four

. (dot) is the wildcard for any character; Chapter Two; Chapter One
. (dot) as a decimal point or period; Chapter Two
.*? Question mark to eliminate greed; Chapter Nine

(?!, California) Negative look-ahead assertion; Chapter Twelve
(?<!Los Angeles, ) Negative look-behind assertion; Chapter Twelve
(?<=...) Look-behind assertion; Chapter Twelve
(?=, California) Look-ahead assertion; Chapter Twelve
? Look-ahead and look-behind assertions; Chapter Twelve
? Negative look-ahead assertion (?!, California); Chapter Twelve
? Optional expressions \S?; Chapter Seven
? Optional match; Chapter Four; Chapter Eleven
? Question mark to eliminate greed .*?; Chapter Nine
?: Do not capture subpattern inside (?:…); Chapter Eight

[^\W] Prevent non-alphanumeric matches; Chapter Eleven
[…] Ranges; Chapter Two
[0-9]+ Repeated range; Chapter Four
[a-z0-9_\.-] Any lowercase letters, numbers, the underline mark, dots, and hyphens; Chapter Eleven
[a-zA-Z0-9] All letters and numeric digits; Chapter Two

\ Backslash not required within range to escape dot .; Chapter Eleven
\ Backslash, escape character; Chapter Two
\. Dot escape sequence; Chapter Two; Chapter Eleven
\b Word match boundary; Chapter Five; Chapter Thirteen
\d Same as [0-9] or [0123456789]; Chapter Two; Chapter Four; Chapter Eleven
\d{1,3} 0 to 9 at least once no more than three times; Chapter Eight
\K Look behind assertion; Chapter Twelve
\p{P} Match any punctuation; Chapter Thirteen
\p{Pe} Match end or close bracket or parenthesis; Chapter Thirteen
\p{Ps} Match start or open bracket or parenthesis; Chapter Thirteen
\p{S} Match any symbol; Chapter Thirteen
\p{Sc} Match any currency symbol; Chapter Thirteen
\p{xx} Properties; Chapter Thirteen
\s Space; Chapter Five
\W any non-alphanumeric character; Chapter Eleven
\w Match any letter or digit, [a-zA-Z0-9]; Chapter Thirteen; Chapter Four; Chapter Two

`n for newline or linefeed; Chapter Five
`r for carriage return; Chapter Five

{2,6} min two and max six of preceding range; Chapter Eleven
{min,max} Match preceding at least min and no more than max times; Chapter Four; Chapter Six; Chapter Seven; Chapter Eight; Chapter Eleven

+ Match preceding 1 or more times; Chapter Two; Chapter Five; Chapter Eleven
+ Similar to the star *, but is used to match one or more; Chapter One

<a href="URL">Link Text</a>; Chapter Ten

Regular Expressions (RegEx) A-C

Alternative matches; Chapter Seven
AutoHotkey Forum; Chapter Eight
AutoHotkey_L RegEx Tester (Ryan's); Chapter One
AutoHotkey_L support; Chapter Thirteen

Backreference; Chapter Six; Chapter Seven; Chapter Eight; Chapter Eleven
Backreference as replacement; Chapter Five
Backreference in the expression; Chapter Five
Backreference to make the match; Chapter Five
Break; Chapter Eight

Case insensitive option; Chapter Five
Changing and rearranging data, RegExReplace(); Chapter One
Circumflex ^ different meanings; Chapter Four
Clipboard := SubStr(Clipboard,2); Chapter Seven
ClipWait command; Chapter Seven; Chapter Eight
ComObjCreate("WinHttp.WinHttpRequest.5.1"); Chapter Eight
ComObjCreate() function; Chapter Eight
Contractions, fix multiple errors; Chapter Six
CountIP++; Chapter Eight

Regular Expressions (RegEx) D-F

Dot (.) not used inside a range; Chapter Two
Dot (.) used inside a range; Chapter Two
Duplicate words in text; Chapter Five

Eliminate loops when possible; Chapter Ten
Eliminating extra spaces; Chapter Five
E-mail address validation; Chapter Eleven
Extracting and replicating data, RegExMatch(); Chapter One
Extracting IP addresses; Chapter Eight
Extracting, Web links from a Web page; Chapter Ten

FileAppend command; Chapter Nine; Chapter Ten
FileDelete command; Chapter Nine; Chapter Ten
FileRead command; Chapter Nine; Chapter Ten
Forcing a number type from a string; Chapter Four
FoundPos; Chapter Two

Regular Expressions (RegEx) G-L

Greed; Chapter Nine

Haystack; Chapter Two
History of Regular Expressions; Chapter One
How RegEx Works; Chapter Two
HTML language; Chapter Nine
HTML source code, stripping out; Chapter Nine
HTML tags; Chapter Ten
HTTP(S):// RegEx; Chapter Ten

i) Option, ignore case; Chapter Thirteen
InStr() function; Chapter Seven
IP address matching; Chapter Eight

Kleene plus +; Chapter One
Kleene star *; Chapter One

Line continuation; Chapter Seven
List of useful RegEx properties \p{xx}; Chapter Thirteen
Locate duplicate words; Chapter Five
Look-ahead assertions; Chapter Twelve
Look-behind assertions; Chapter Twelve
Loop command; Chapter Eight; Chapter Ten
Loop, using RegExMatch() in; Chapter Two

Regular Expressions (RegEx) M-O

Mark double words; Chapter Five
Matching contractions; Chapter Five
Matching more than one IP address; Chapter Eight
Matching the end of a string; Chapter Four
Matching words only; Chapter Five
MatchObject; Chapter Five; Chapter Eight; Chapter Eleven

Needle in a haystack; Chapter Two
NeedleRegEx; Chapter Two
Non-greedy mode; Chapter Ten
Numeric digit wildcard (\d); Chapter Three
Numeric location in Haystack; Chapter Two

O) MatchObject Option; Chapter Five; Chapter Eight; Chapter Eleven
Object Oriented Programming (OOP); Chapter Five
Object properties; Chapter Five
Optional \S? expressions; Chapter Seven

Regular Expressions (RegEx) P-R

P) Position Option; Chapter Five
Parse a number from the title of a window; Chapter Three
Properties, using in RegEx \p{xx}; Chapter Thirteen
Pseudo-array; Chapter Eight
Punctuation mark, match; Chapter Thirteen

Ranges in RegEx matches[…]; Chapter Three; Chapter Two
Reference online RegEx; Chapter Two
Reformatting data, RegExReplace(); Chapter Three
RegEx history; Chapter One
RegEx Options; Chapter Five
RegEx Quick Reference; Chapter Two
RegEx Tester (Robert Ryan); Chapter Three; Chapter Eight
RegEx Tester script; Chapter One
RegEx Tester using; Chapter Five
RegExMatch() and RegExReplace(), differences and uses; Chapter Two
RegExMatch() for extracting data; Chapter Three
RegExMatch() function; Chapter One; Chapter Two; Chapter Three; Chapter Four; Chapter Eight; Chapter Eleven
RegExMatch() is for mining, extracting, and replicating data; Chapter One
RegExMatch(), using in Loop; Chapter Two
RegExReplace(); Chapter Two
RegExReplace(); Chapter One
RegExReplace() for correcting data; Chapter Three
RegExReplace() for reformatting data; Chapter Three
RegExReplace() is for changing and rearranging; Chapter One
RegExReplace(); Chapter One; Chapter Three; Chapter Four; Chapter Seven; Chapter Nine
Regular Expression testing app; Chapter One
Regular Expressions (RegEx or RegExp); Chapter Two
Remove all non-numeric characters; Chapter Three
Remove all of the letters (upper and lowercase) in a variable; Chapter Four
Removing unwanted characters; Chapter Four
Repeated expression in parentheses; Chapter Eight
Retrieval of Web page data; Chapter Eight
Retrieve IPs geographic location; Chapter Eight
Run command; Chapter Nine; Chapter Ten
Ryan's Regular Expression testing app; Chapter One

Regular Expressions (RegEx) S-T

Saving RegEx matches to a variable; Chapter Two
SendInput, ^c; Chapter Seven
SetFormat command; Chapter Four
Sleep command to delay script execution; Chapter Eight
StringGetPos command; Chapter Seven
StringReplace command; Chapter Nine
StringTrimRight; Chapter Three
Stripping out HTML code; Chapter Nine
StrLen() function; Chapter Eight
Subpattern (…); Chapter Ten; Chapter Eleven
Sub-reference; Chapter Ten
SubStr() function; Chapter Four; Chapter Seven
SubStr(Clipboard,1,1); Chapter Seven
Swapping contractions in text; Chapter Seven
Swapping letters in text; Chapter Seven
Swapping two words in text; Chapter Seven

Test script, Ryan's; Chapter Two
Testing a RegEx; Chapter Eleven
Testing RegEx, a simple script; Chapter Eleven

Regular Expressions (RegEx) U-W

UrlDownloadToFile command; Chapter Eight; Chapter Nine; Chapter Ten

Validating number fields; Chapter Four
Various RegEx options; Chapter Two

Web links from a Web page, extracting; Chapter Ten
Web to retrieve the IP's geographic location; Chapter Eight
Wildcard, dot (.); Chapter Eight
Word boundary \b; Chapter Five

*          *           *

This Beginner's Guide to Using Regular Expressions in AutoHotkey is not a beginning level AutoHotkey book, but an introduction to using Regular Expressions in AutoHotkey (or most other programming languages). To get the most from this book you should already have a basic understanding of AutoHotkey (or another programming language). Regular Expressions (RegEx) are a powerful way to search and alter documents without the limitations of most of the standard matching functions. At first, the use of RegEx can be confusing and mysterious. This book clears up the confusion with easy analogies for understanding how RegEx works and examples of practical AutoHotkey applications. "Regular Expressions in AutoHotkey" will take you to the next level in AutoHotkey scripting while adding more flexibility and power to your Windows apps. (This book is also available at Amazon.com)

*                    *                    *


ComputorEdge