mardi 28 juin 2016

Find expression at start of line or after a punctuation

This has been bothering me for the past few days and I can't seem to find the answer. Consider the following:

I have a string called "options" which is in the form: "xxx=true&yxxx=true&zzz=false" (yes, like an URL query).

I have pattern matchers set up like so:

Pattern pattern1 = Pattern.compile("xxx=true");
Pattern pattern2 = Pattern.compile("yxxx=true");
Pattern pattern3 = Pattern.compile("zzz=true");

My problem comes with differentiating between the second and first pattern, since pattern1 finds a match in the yxxx=true case since it contains the "xxx=true" string. I've looked everywhere, and could get away with splitting the first pattern to "&xxx=true" and "^xxx=true" to cover the "start of line" and every other case, but I just know there must be some other way to do this.

Aucun commentaire:

Enregistrer un commentaire