Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Providejavaawaytocheckthattwostringsareidenticalonlywithregexdifferences

Let's assume we have the following regex expression java:

String regex = "^(AB)?\d{2}(CD)+$"

And we have the following strings that matches the regex:

String one = "AB23CD"; -> one.matches(regex) = true;
String two = "AB23CDCD"; -> two.matches(regex) = true;
String three = "23CDCD"; -> three.matches(regex) = true;

String four = "45CD"; -> four.matches(regex) = true;

Is there a way to check that the strings have the same basis? So I search a method to check that String one, two and three have the same basis for the specified regex. For example:

one.hasSameBasis(regex, two) = true;
two.hasSameBasis(regex, four) = false;

Is there a way in Java? Or isn't it possible due to the complexity of regex?

Comments