SQL Server REGEX Complete Tutorial with Practice Exercises

2

SQL Server REGEX Complete Tutorial with Practice Exercises, SQL Regular Expressions and Pattern Matching, Wildcards.

Course Description

In this course, we will learn about SQL REGEX operations in SQL Server database.

We will learn about pattern matching and how to use the wildcards.

We will learn how to use the following wildcards –

% – Any string of zero or more characters.

_ (underscore) Any single character.

[ ] Any single character within the specified range

[^] Any single character not within the specified range

All examples are base don the AdventureWorksLT database from Microsoft.

The table is SalesLt.Product.

You can download it from the Microsoft Website.

Select * from SalesLT.Product

Examples –

— % – Any string of zero or more characters.

Example 1 –    Name with ‘Bike’

— _ (underscore) Any single character.

Example 2 –  Second character is ‘R’

—   Third character is ‘-‘ and 4th character is ‘U’

Check for Product Number pattern

Example 3 –   Any 2 characters followed by ‘-‘ followed

Example 4 –   by any 4 characters followed by ‘-‘ followed

Example 5 –   by any single character  – HL-U509-R

— [ ] Any single character within the specified range

Example 6 –    Above pattern with last char L or M

Example 7 –   Above pattern with last char between L and S

Example 8 –    Above pattern with last char between L and R

— [^] Any single character not within the specified range

Example 9 –    Above pattern with last char not between L and R

Example 10 –     Product number not starting with F

Example 11 –    Product number not starting with F or H

Example 12 –     Product NUmber not starting between A to H.

Example 13 – Data(Size) is Only One Character and Value is from A to Z

Example 14 – Data(Size) is Two Characters and Values are from A to Z

Example 15 – Text(rowguid) Rows Starting with a Number

Example 16 – Find a Number Pattern –

— Product Number with 4th and 5th chars as numbers

Example 17 – Number(List Price) with two decimal places ending in 2

— Using the Not Character for Regex with T-SQL

Example 18 Product Number – after 1st hyphen has either numbers or special characters

Example 19 – Name has Only alphabetic characters

Example 20 – Name has No special characters


We will be happy to hear your thoughts

Leave a reply

Online Courses
Logo
Register New Account
Compare items
  • Total (0)
Compare
0