简体   繁体   中英

How to find a specific word using Regex?

I`m trying to select DataTable rows using regex. I want to found all rows that have only the word "Venta" and omit "Renta/Venta" and also "Renta".

Examples of possibles strings:

"whatever whatever Venta/Renta whatever"

"whatever whatever Venta whatever "

"whatever whatever Renta whatever "

I only want to select the string that only have "Venta" alone. Now I using "(?!Renta/Venta)Venta" but still selects the rows that have "Renta/Venta".

使用空格字符( \\s ):

/(^|\s)Venta(\s|$)/

在这里检查: https : //regex101.com/r/Ja7Vg8/1

.*\bVenta\b[^\/].*

If the string are built that way, then you can use a regex with negative lookahead like this:

.*Venta(?!\/Renta).*

working demo

Keep in mind that it won't work if the string is:

whatever Renta whatever Venta whatever

So, if strings like above are present, then you can use a trick like this:

^(.(?!Renta))+$

Working demo

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