---
title: "How to test regular expressions in SQL without using database table"  
description: "How to test regular expressions in SQL without using database table"  
author: "Sandra Emily"  
published: 2023-07-30  
updated: 2023-07-31  
canonical: https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to test regular expressions in SQL without using database table

How to [test](https://yourviews.mindstick.com/story/1427/explosive-facts-about-trinity-test-world-s-first-nuclear-bomb) [regular](https://www.mindstick.com/forum/220/problem-in-regular-expression-in-javascript) [expressions](https://www.mindstick.com/forum/33876/what-is-the-syntax-for-lambda-expressions-in-vb-dot-net) in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) without using [database table](https://answers.mindstick.com/qa/113649/what-is-the-database-table-structure-of-url-analyzer-details-to-store)

## Replies

### Reply by Aryan Kumar

Sure, here is how to test regular expression in SQL without using a [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap):

SQL

```plaintext
DECLARE @pattern VARCHAR(255);
DECLARE @string VARCHAR(255);

SET @pattern = '^[a-z]+$';
SET @string = 'hello';

IF REGEXP_LIKE(@string, @pattern)
BEGIN
PRINT 'The string matches the pattern.';
END
ELSE
BEGIN
PRINT 'The string does not match the pattern.';
END;
```

This query will first define two variables: `@pattern` and `@string`. The `@pattern` variable will store the regular expression that you want to test. The `@string` variable will store the string that you want to test against the regular expression.

The next step is to use the `REGEXP_LIKE()` function to test the string against the regular expression. The `REGEXP_LIKE()` function returns `TRUE` if the string matches the regular expression and `FALSE` if the string does not match the regular expression.

If the string matches the regular expression, the `IF` statement will print the message "The string matches the pattern." Otherwise, the `IF` statement will print the message "The string does not match the pattern."

To run the query, you can copy and paste it into a SQL query tool, such as SQL Server Management Studio or MySQL Workbench.


---

Original Source: https://www.mindstick.com/forum/159366/how-to-test-regular-expressions-in-sql-without-using-database-table

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
