开发者

What is the right regex that matches one of the substrings at the end of the word in Java?

开发者 https://www.devze.com 2023-03-10 06:26 出处:网络
I ne开发者_开发百科dd the check whether the word ends with one of the_LNG , _DBL, _STR . My regex is

I ne开发者_开发百科dd the check whether the word ends with one of the _LNG , _DBL , _STR . My regex is

"_[(LNG|DBL|STR)]$"

but does work . Following must match but did'nt work. (I use java)

PARAM_LNG

I have tried following

"[(_LNG|_DBL|_STR)]$"

but it matchs with following although it has no underscore.

PARAMLNG

Can anyone show the right regex? Thanks.


Don't use [], that's a character class specification.

"_(LNG|DBL|STR)$"

Note that this will only match at the end of the string. Try:

"_(LNG|DBL|STR)\b"

to match any word ending with those suffixes inside a string.

0

精彩评论

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