import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?:for\\(.*<\\W?)(([\\w]+)\\.?)+(?:\\[?)|(?:\\.length)";
final String string = "for($j = 0; $j < incomingData.customer['data'].length; $j++){\n\n"
+ "for(c=a.children.length-1;0<=c;c--)d\n\n"
+ "for(l=0;l<g.length;l++){d=g[l]\n\n"
+ "for(h in b)if(!h.match(d||/margin|text\\-align|width|border|padding/i))if(g)g=!1;else{var l=new CKEDITOR.htmlParser.element(\"span\");l.attributes.style=h+\":\"+b[h];c.add(l);c=l;delete b[h]}CKEDITOR.tools.isEmpty(b)?delete a.attributes.style:a.attributes.style=CKEDITOR.tools.writeCssText(b);for(b=0;b<e.length;b++)c.add(e[b])},sortStyles:function(a){for(var b=[\"border\",\"border-bottom\",\"font-size\",\"background\"],c=m.parseCssText(a.attributes.style),d=m.objectKeys(c),e=[],g=[],h=0;h<d.length;h++)\n\n"
+ "for(var f=0,n=0,l=0,p,e=a.$.rows.length;l<e;l++)\n\n"
+ "for(var i = 0; i < this.audioLayerControl.listOfSequenceEditors.length; ++i)\n"
+ " ";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html