IsRegexMatch
Checks whether a string matches a Regular Expression pattern.
- Free Function
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
SELECT SQLHTTP.net.IsRegexMatch( @Text, @RegexPattern)
Name | Type | Description |
---|---|---|
@Text | nvarchar(MAX) | String to be tested for a match. |
@RegexPattern | nvarchar(4000) | String expression containing a regex expression. See Regular Expression Language – Quick Reference for more information. |
bit
0 = Text does NOT MATCH the regular expression pattern
1 = Text MATCHES the regular expression pattern
The following is a handy example of validating an email:
1 2 3 4 5 6 7 8 9 |
DECLARE @Text nvarchar(MAX) DECLARE @RegexPattern nvarchar(4000) SET @Text = 'support@SQLHTTP.net' SET @RegexPattern = '\w+([-+.'']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*' SELECT SQLHTTP.net.IsRegexMatch(@Text, @RegexPattern) |
1 2 3 4 5 |
----- 1 |