regexMatches() : Find All Pattern Matches
On this page
Summary
Find all occurrences of a regular expression pattern in a string.
Signature
regexMatches(str, pattern)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
str |
String | Yes | The string to search |
pattern |
String | Yes | The regular expression pattern |
Returns
Type: Array of strings
An array containing all matches found.
Examples
Extract All Numbers
Data:
doc.Params["model"] = new {
text = "Order 123 contains 45 items at $67.89"
};
Output:
<ul>
<li>Number: 123</li>
<li>Number: 45</li>
<li>Number: 67</li>
<li>Number: 89</li>
</ul>
Extract Email Addresses
Data:
doc.Params["model"] = new {
text = "Contact john@example.com or jane.doe@company.co.uk for details"
};
Output:
<h3>Found Emails:</h3>
<p>john@example.com</p>
<p>jane.doe@company.co.uk</p>
Extract Hashtags
Data:
doc.Params["model"] = new {
post = "Great day! #travel #adventure #nature #photography"
};
Output:
<div class="tags">
<span class="tag">#travel</span>
<span class="tag">#adventure</span>
<span class="tag">#nature</span>
<span class="tag">#photography</span>
</div>
Extract URLs
Count Matches
Data:
doc.Params["model"] = new {
text = "ABC123XYZ456"
};
Output:
<p>Found 6 digits</p>
Notes
- Uses .NET regex syntax
- Returns array of all matches (not just first)
- Returns empty array if no matches found
- Backslashes must be escaped:
\\d,\\w, etc. - Use with `` to iterate matches
- For testing if match exists, use
regexIsMatch() - For replacement, use
regexSwap()
Common Patterns
| Pattern | Description | Example |
|---|---|---|
\\d+ |
One or more digits | 123, 45 |
\\w+ |
Word characters | hello, test123 |
[A-Z]+ |
Uppercase letters | ABC, XYZ |
#\\w+ |
Hashtags | #tag1, #tag2 |
@\\w+ |
Mentions | @user1, @user2 |
\\$\\d+\\.\\d{2} |
Currency | $19.99, $100.00 |