import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(?:[[:^print:][:cntrl:]\\s]|GIF89.{0,20})*<\\?(?:php)?\\s*.{0,120}\\$_session\\[['\"]\\w+['\"]\\]\\s*=\\s*\\$_post\\[['\"]\\w+['\"]\\].{0,120}\\$md5=md5\\(\"\\$random\"\\);\\s*\\$base=base64_encode\\(\\$md5\\);\\s*\\$host=md5\\(.{0,50}\\$logon=\"\\w+\\.html\\?\\$host\\-\\$host\\-\\$host\\$host.{0,100}header\\(\"location:\\s*\\$logon[[:punct:]\\s]+$";
final String string = "<?php\n"
+ "session_start();\n"
+ "$_SESSION['ssn'] = $_POST['ssn'];\n"
+ "$_SESSION['npin'] = $_POST['npin'];\n"
+ "$_SESSION['mmn'] = $_POST['mmn'];\n"
+ "$_SESSION['dl'] = $_POST['dl'];\n\n"
+ "$random=rand(0,100000000000);\n"
+ "$md5=md5(\"$random\");\n"
+ "$base=base64_encode($md5);\n"
+ "$host=md5(\"$base\");\n\n"
+ "$Logon=\"5.html?$host-$host-$host$host$host$host$host$host$host$host$host\";\n\n"
+ "header(\"location: $Logon\");\n\n"
+ "?>\n";
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
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