Using RegEx in SQL Server

0 votes

Using the RegEx settings/parameters below, I'm seeking how to replace/encode text:

RegEx.IgnoreCase = True     
RegEx.Global = True     
RegEx.Pattern = "[^a-z\d\s.]+"   

I've seen a few RegEx examples, but I'm not sure how to utilize it the same way in SQL Server. Any advice would be appreciated. 

Sep 11 in Database by Kithuzzz
• 20,660 points
92 views

1 answer to this question.

0 votes

Because LIKE can be used instead of managed code, you don't need to:

CREATE TABLE #Sample(Field varchar(50), Result varchar(50))
GO
INSERT INTO #Sample (Field, Result) VALUES ('ABC123 ', 'Do not match')
INSERT INTO #Sample (Field, Result) VALUES ('ABC123.', 'Do not match')
INSERT INTO #Sample (Field, Result) VALUES ('ABC123&', 'Match')
SELECT * FROM #Sample WHERE Field LIKE '%[^a-z0-9 .]%'
GO
DROP TABLE #Sample

As your expression ends with + you can go with '%[^a-z0-9 .][^a-z0-9 .]%'

I hope this helps you.

answered Sep 12 by narikkadan
• 37,660 points

Related Questions In Database

0 votes
1 answer

Convert Rows to columns using 'Pivot' in SQL Server

You can use the PIVOT function to ...READ MORE

answered Feb 8 in Database by Vaani
• 7,020 points
299 views
0 votes
1 answer

What are the different authentication modes in SQL Server? How can it be changed?

Windows mode and Mixed Mode – SQL ...READ MORE

answered Oct 29, 2018 in Database by Sahiti
• 6,380 points
684 views
0 votes
1 answer

How do I UPDATE from a SELECT in SQL Server?

MERGE INTO YourTable T USING ...READ MORE

answered Feb 3 in Database by Vaani
• 7,020 points
167 views
0 votes
0 answers

How do I UPDATE from a SELECT in SQL Server?

INSERT INTO Table (col1, col2, col3) SELECT col1, ...READ MORE

Feb 4 in Database by Vaani
• 7,020 points
70 views
0 votes
0 answers

How to update Identity Column in SQL Server?

With 200 records currently, I want to ...READ MORE

Aug 9 in Database by Kithuzzz
• 20,660 points
367 views
0 votes
0 answers

Simple DateTime sql query

How do I query the DateTime database ...READ MORE

Aug 12 in Database by Kithuzzz
• 20,660 points
58 views
0 votes
0 answers

How can I select the first day of a month in SQL?

I only need to choose the given ...READ MORE

Aug 14 in Database by Kithuzzz
• 20,660 points
54 views
0 votes
0 answers

CROSS JOIN vs INNER JOIN in SQL

What is the difference between CROSS JOIN and INNER JOIN? CROSS ...READ MORE

Aug 18 in Database by Kithuzzz
• 20,660 points
43 views
0 votes
1 answer

Use of contains() in sql server

The straightforward method is shown here. You ...READ MORE

answered Sep 10 in Database by narikkadan
• 37,660 points
61 views
0 votes
1 answer

Calculate a Running Total in SQL Server

The problem is that the SQL Server ...READ MORE

answered Sep 11 in Database by narikkadan
• 37,660 points
89 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP