import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\S+) = .*VOS_Malloc\\(\\S+, .*\\);.*memset_s\\s*\\([^,]*\\1[^,]*, ([^,]+), [^,]+, ([^,]+)\\);";
final String string = " pNewBuf = (CHAR *)VOS_Malloc(VASP_AAA_MID, tmp_length * xxx);\n"
+ " if (NULL == pNewBuf) {\n"
+ " (VOID)VOS_Free(tmp_buf);\n"
+ " *buf = NULL;\n"
+ " return VOS_ERR;\n"
+ " }\n"
+ " (VOID)memset_s ((CHAR *)(pNewBuf), tmp_length, 0, tmp_length);\n\n"
+ " nRet = memcpy_s ((VOID *)(pNewBuf), (VOS_UINT32)tmp_length, (VOID *)(tmp_buf), (VOS_UINT32)tmp_offset);\n"
+ " VOS_DBGASSERT(nRet == VOS_OK);\n"
+ " (VOID)VOS_Free(tmp_buf);\n\n"
+ " pNewBuf = (CHAR *)VOS_Malloc(VASP_AAA_MID, tmp_length * xxx);\n"
+ " if (NULL == pNewBuf) {\n"
+ " (VOID)VOS_Free(tmp_buf);\n"
+ " *buf = NULL;\n"
+ " return VOS_ERR;\n"
+ " }\n"
+ " (VOID)memset_s ((CHAR *)(pNewBuf), tmp_length * 3, 0, tmp_length);\n";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE | Pattern.DOTALL);
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