简体   繁体   中英

Regex to check if text contains one of two words and preceding number

Now i need help of some regex pros since i'm normally trying to avoid them if possible. I need it in a sql-server query where i don't see any other option than using regex.

This text must be a match:

####:;Approval:;EC 33/37:1-  goodwill validation

because it contains one of those sub-strings

  • CASEID
  • Goodwill

and before it there must be 1- . I could use this sql query:

WHERE d.REMARKS LIKE '%1-%CASEID%' OR d.REMARKS LIKE '%1-%Goodwill%'

but the problem is that it also matches if there is another digit before the 1 which makes it a different number. So before the 1 there can be any letter but no digit.

This is what i've t ried without success :

.*[^0-9]1-.*(CASEID|Goodwill).*

The C# tag because i'm using C# SqlFunction for the regex.

I think you can use normal LIKE :

LIKE '%[^0-9]1-%CASEID%'

This has a down-side of assuming the 1 isn't the first character.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM