groupstudent
groupstudent

Reputation: 4297

Regex in Java: How do I know if a specific part of Regex matches or not?

I am trying to implement a paper. The author has a pattern:

u*v+w+

And he said if 'u*' is not empty,"blablabla" else empty another choice. But how could I know if 'u*' is matched or not in the whole part?

Upvotes: 1

Views: 41

Answers (1)

anubhava
anubhava

Reputation: 785561

Use captured groups e.g. (u*)v+w+ as regex and then check matcher.group(1) to determine whether u* matched or not.

Upvotes: 1

Related Questions