Cuder_VN
Cuder_VN

Reputation: 25

Regex in java - catch the dot

How to add the dot to the last of regex and it's is the optional like:

public static final String REGEX_HASHTAGS = "([^|\s|>]*[a-z]{2}[0-9]+(\s|$|<)+)";

i want to catch the string like: cx10 or cx10.

Upvotes: 0

Views: 109

Answers (1)

fge
fge

Reputation: 121840

Try this regex:

public static final String REGEX_HASTAGS
    = "\\b[a-z]{2}[0-9]+\\.?\\b";

\b is the word anchor, and looks like what you want given your initial regex.

Upvotes: 1

Related Questions