I am trying to capture text that is matched by lookbehind.
My code :
private static final String t1="first:\\\w*";
private static final String t2="(?<=\\w+)=\\".+\\"";
private static final String t=t1+'|'+t2;
Pattern p=Pattern.compile(t);
Matcher m=p.matcher("first:second=\\"hello\\"");
while(m.find())
System.out.println(m.group());
The output:
first:second
="hello"
I expected:
first:second
second="hello"
How can I change my regex so that I could get what I expect.
Thank you
Why don't you just use one regex to match it all?
And then simply use one match, and use the groups 1 and 2 for the first expected row and the groups 2 and 3 for the second expected row.
I modified your example to be compilable and showing my attempt: