G3REGEXP - Quick Reference Guide
Fast reference for using RegExp (Regular Expressions) in G3 AxonASP
Creating a RegExp Object
Dim regex
Set regex = Server.CreateObject("G3REGEXP")
' Or use alias:
Set regex = Server.CreateObject("REGEXP")
Properties (Using SetProperty/GetProperty)
| Property |
Type |
Description |
Example |
| Pattern |
String |
The regular expression pattern |
regex.SetProperty "pattern", "\d+" |
| IgnoreCase |
Boolean |
Case-insensitive matching (default: False) |
regex.SetProperty "ignorecase", True |
| Global |
Boolean |
Find all matches (default: False for first match only) |
regex.SetProperty "global", True |
| MultiLine |
Boolean |
^ and $ match line boundaries (default: False) |
regex.SetProperty "multiline", True |
Methods
Test(inputString) → Boolean
Check if the pattern matches the string. Returns True or False.
Example:
Dim regex, result
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "^\d{3}-\d{4}$"
result = regex.Test("555-1234") ' Returns: True
Execute(inputString) → RegExpMatches Collection
Find all (or first) matches and return a collection of matches.
Example:
Dim regex, matches, match, i
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "\d+"
regex.SetProperty "global", True
Set matches = regex.Execute("I have 10 apples and 25 oranges")
For i = 0 To matches.Count - 1
Set match = matches.Item(i)
Response.Write match.Value & " at index " & match.FirstIndex & "
"
Next
' Output:
' 10 at index 8
' 25 at index 25
Match Object Properties:
Value - The matched text
FirstIndex or Index - Position in string (1-based)
Length - Length of the match
Count - Total number of matches (on collection)
Replace(inputString, replacement) → String
Replace matched patterns with replacement text.
Example:
Dim regex, result
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "\d+"
regex.SetProperty "global", True
result = regex.Replace("Order 123 with 5 items", "[NUM]")
' Result: "Order [NUM] with [NUM] items"
Common Patterns
| Pattern |
Description |
Example |
\d+ |
One or more digits |
123, 2024 |
[a-z]+ |
One or more lowercase letters |
hello, world |
^text$ |
Exact match (start and end) |
Matches "text" exactly |
\w+ |
One or more word characters |
word, test_var |
[aeiou] |
Any vowel |
a, e, i, o, u |
\b\w+\b |
Complete words |
Uses word boundaries |
Practical Examples
1. Email Validation
Function IsValidEmail(email)
Dim regex
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
IsValidEmail = regex.Test(email)
End Function
If IsValidEmail("user@example.com") Then
Response.Write "Valid email"
End If
2. Extract All Numbers from Text
Dim regex, matches, i
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "\d+"
regex.SetProperty "global", True
Set matches = regex.Execute("Invoice #2024001 for $1500.99")
Response.Write "Numbers found: "
For i = 0 To matches.Count - 1
If i > 0 Then Response.Write ", "
Response.Write matches.Item(i).Value
Next
' Output: "Numbers found: 2024001, 1500, 99"
3. Clean Up Text
Dim regex, result
Set regex = Server.CreateObject("G3REGEXP")
' Remove extra whitespace
regex.SetProperty "pattern", "\s+"
regex.SetProperty "global", True
result = regex.Replace("hello world", " ")
' Result: "hello world"
' Remove HTML tags
regex.SetProperty "pattern", "<[^>]+>"
result = regex.Replace("
Hello
", "")
' Result: "Hello"
4. Phone Number Validation
Dim regex
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "^(\+1)?[-.\s]?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}$"
' All of these would match:
' 555-123-4567
' (555) 123-4567
' 5551234567
' +1-555-123-4567
5. Replace with Multiple Occurrences
Dim regex, result
Set regex = Server.CreateObject("G3REGEXP")
regex.SetProperty "pattern", "[aeiou]"
regex.SetProperty "ignorecase", True
regex.SetProperty "global", True
result = regex.Replace("Hello World", "*")
' Result: "H*ll* W*rld"
Common Metacharacters
| Metacharacter |
Meaning |
. |
Any character (except newline) |
* |
Zero or more of previous character |
+ |
One or more of previous character |
? |
Zero or one of previous character |
^ |
Start of string |
$ |
End of string |
[...] |
Character class (one of ...) |
[^...] |
Negated character class (not ...) |
\d |
Digit (0-9) |
\w |
Word character (a-z, A-Z, 0-9, _) |
\s |
Whitespace |
Test Your Patterns
Visit test_regexp.asp for a comprehensive test suite with examples of all features.