Nishant
Nishant

Reputation: 21914

How to query for a pattern in a DB table with HTML content in the particular column ?

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?

Upvotes: 0

Views: 60

Answers (2)

mathematical.coffee
mathematical.coffee

Reputation: 56905

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.

Upvotes: 1

Toto
Toto

Reputation: 91385

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)

Upvotes: 1

Related Questions