I made a regular expression: https://regex101.com/r/ToCwrE/2/
All it should do, is get out the function's parameters. I am trying with capture groups to achieve this.
[\s]*javascript:[\s]*m\((-?\d+)[\s]*,[\s]*(-?\d+)[\s]*,[\s]{0,}encodeURIComponent\(\'([^\']+)*\'\)[\s]*,[\s]*(-?\d+)\)[\s]*
Tried it on:
javascript:m(53009,2,encodeURIComponent('7711T'), 22)
javascript:m(52992,2,encodeURIComponent('3013'), 2)
javascript:m(10440,2,encodeURIComponent('F Series'), 11)
javascript:m(53022,2,encodeURIComponent('C 12045'), 85)
javascript:m(53045,2,encodeURIComponent('Prox 8441'), 16)
javascript:m(26016,2,encodeURIComponent('Vard asd .ious'), 22)
Using the site regex101 and a few similar ones, it correctly returns the matched groups. However when I am trying to use it in Java, it simply won't match the capture groups and only returns the whole text.
If I copy paste it with IDEA, It automatically gets escaped (replaces \ to \):
Pattern pattern = Pattern.compile("[\\s]*javascript:[\\s]*m\\((-?\\d+)[\\s]*,[\\s]*(-?\\d+)[\\s]*,[\\s]{0,}encodeURIComponent\\(\\'([^\\']+)*\\'\\)[\\s]*,[\\s]*(-?\\d+)\\)[\\s]*");
Matcher m = pattern.matcher("javascript:m(53022,2,encodeURIComponent('Cr 12045'), 85)");
List<String> groups = new ArrayList<>();
while (m.find()) {
groups.add(m.group());
}
groups;
What am I missing? How should the regex be converted to get it working in Java?