0

We have a table called with a column which is purely HTML. I need to do a find a pattern like [4digit max]_[6digit number]. Is that possible?

3
  • What do you mean by the 'max' in '4digit max'? You mention 'DB' in your question title and 'database' in the tags, but are you trying to do the regex using the database syntax? In that case, what sort of database is it, mySQL? We need more information! Commented Dec 21, 2011 at 13:09
  • Is 4digit max 0 to 4 digits or 1 to 4 digits? Commented Dec 21, 2011 at 13:34
  • We are using SQL Server Studio - Provided by Microsoft Commented Dec 22, 2011 at 7:20

2 Answers 2

1

For Microsoft SQL Server, see here:

select * from Notif_Template
where dbo.regexMatch( Notif_body, '([^0-9]|^)[0-9]{1,4}_[0-9]{6}([^0-9]|$)' ) = 1;

dbo.regexMatch returns if there's a match and 0 otherwise.

Sign up to request clarification or add additional context in comments.

Comments

1

As you didn't say wich database, here is a way to do it with PostgreSQL:

SELECT SUBSTRING('abc1234_123456xyz', '(?:[^0-9]|^)([0-9]{1,4}_[0-9]{6})(?:[^0-9]|$)');

  substring
-------------
 1234_123456
(1 row)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.