[Posting this question because I could not find any question matching my scenario, please point me to the post if this is already discussed, I will delete this post.]
Trying to create a regex to match string app=myApp
in long string separated by either ,
or ;
.
My regex fails if the patterns is at end and not terminated by by either ,
or ;
.
This is the regex I have used: [^.][app|APP]=(.*?)[,|;]
this works for the following strings:
env=prod;app=myApp;app.secure=yes
app=myApp;app.secure=yes
But does not work for following:
env=prod;app=myApp
app=myApp
Here is my code:
Pattern pattern = Pattern.compile("[^.][app|APP]=(.*?)[,|;]");
Matcher matcher = pattern.matcher(stringVar);
if (matcher.find()) {
return matcher.group(1);
}
I have also tried:
[^.][app|APP]=(.*?)[,|;|$]
but still no luck.