开发者

Need regex for matching unquoted whole words excluding a list of set words

开发者 https://www.devze.com 2023-03-20 10:42 出处:网络
Given this exact string: Name = \"John\" AND Country = \"USA\" I want two matches returned: Name Country I want to match all unquoted whole words as long as they are not in a short list of defin

Given this exact string:

Name = "John" AND Country = "USA"

I want two matches returned:

Name
Country

I want to match all unquoted whole words as long as they are not in a short list of defined words (e.g. AND, OR)

This wil开发者_如何学Gol be used in a .NET environment.


This will match any word consisting of alphanumeric and _ characters that is not terminated by a ". Excluding the | delimited elements in the (?! ).

It should serve your purposes.

(?<!")\b(?!excludethis|andthis|andthisone|andthat|thistoo|AND)\w+\b(?!")

Warning, this will match Tome and and in Country = "Sao Tome and Principee"

0

精彩评论

暂无评论...
验证码 换一张
取 消