import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "class [A-Za-z_$]*\\s*\\{";
final String string = "class Entity\n"
+ "{\n"
+ " constructor(game,imageURL)\n"
+ " {\n"
+ " this.game = game;\n"
+ " this.sprite = new Sprite(this.game.c,imageURL);\n"
+ " \n"
+ " }\n"
+ " \n"
+ " \n"
+ " draw(depth,offset,textureSize,textureCoordinates,offsetX=0)\n"
+ " {\n"
+ " let scaleFactors = {\n"
+ " 1:1,\n"
+ " 2:0.65,\n"
+ " 3:0.45\n"
+ " };\n"
+ " let scaleFactor = scaleFactors[depth];\n"
+ " \n"
+ " let x = Math.floor(offset.x + textureCoordinates[0] + (textureSize[0] / 2) - (this.sprite.image.width * scaleFactor / 2));\n"
+ " let y = Math.floor(offset.y + textureCoordinates[1] + (textureSize[1] / 2) - (this.sprite.image.height * scaleFactor) + 6 * scaleFactor);\n"
+ " \n"
+ " x = x + offsetX * scaleFactor;\n"
+ " \n"
+ " let width = Math.floor(this.sprite.image.width * scaleFactor);\n"
+ " let height = Math.floor(this.sprite.image.height * scaleFactor);\n"
+ " \n"
+ " let entityFades = {\n"
+ " 1:1,\n"
+ " 2:0.5,\n"
+ " 3:0.1\n"
+ " }\n"
+ " let filter = '';\n"
+ " if(this.game.level.entities.fadeType === 'darken')\n"
+ " {\n"
+ " filter += 'brightness('+entityFades[depth]+')';\n"
+ " }\n"
+ " \n"
+ " this.sprite.draw(\n"
+ " x,\n"
+ " y,\n"
+ " width,\n"
+ " height,\n"
+ " 0,\n"
+ " 0,\n"
+ " this.sprite.image.width,\n"
+ " this.sprite.image.height,\n"
+ " filter\n"
+ " );\n"
+ " }\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