Build a regexp like this :
.+?(r).*
where r
is you regexp.
Java Code
String s;// Your string
String r;// Your regexp
Pattern p = Pattern.compile(String.format(".+?(%s).*",r));
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group(1));
}
Note
I assume your regexp will be matched only one time in your string s
.
1
solved How do you extract a substring from a string based on an input regex [closed]