Gok Demir
Gok Demir

Reputation: 1402

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

I nedd 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.

Upvotes: 1

Views: 51

Answers (1)

Mat
Mat

Reputation: 206679

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.

Upvotes: 5

Related Questions