Safe assembly CLR database project with some basic text functions
regex.Replace (@TextString, @RegexPattern, @ReplaceString)
- returns a new string with the matched pattern replaced
SELECT regex.Replace('This is a test', '\s+', ' ') as Result| Result |
|---|
| This is a test |
regex.IsMatch (@TextString, @RegexPattern)
- returns
Trueif a match is found, elseFalse
SELECT regex.IsMatch('This is a test', '[\w]+') AS Result
UNION ALL
SELECT regex.IsMatch('This is a test', '[\d]+')| Result |
|---|
| 1 |
| 0 |
regex.Match (@TextString, @RegexPattern)
- returns the first match if any, otherwise
NULL
SELECT regex.Match('This is a test', '[\w]+') AS Result
UNION ALL
SELECT regex.Match('This is a test', '[\d]+')| Result |
|---|
| This |
| NULL |
regex.Matches (@TextString, @RegexPattern)
- returns all matches
- idx = position in string
- value = matched string
SELECT idx, value FROM regex.Matches('This is a test', '[\w]+')| idx | value |
|---|---|
| 0 | This |
| 5 | is |
| 8 | a |
| 10 | test |