Preg_match PHP to java translation

回眸只為那壹抹淺笑 提交于 2019-12-05 11:49:46

To implement a function as you did in your code:

final String pattern = "[0-9A-F\\-]{44}";
public static boolean pregMatch(String pattern, String content) {
    return content.matches(pattern);
}

And then you can call it as:

if (pregMatch(pattern, line)) {
    //DO ACTION
}

You don't need the parenthesis in your pattern because that just creates a match group, which you are not using. If you need access to back references, you would need the parenthesis an a more advanced regex code using Pattern and Matcher classes.

You could just use String.matches()

if (line.matches("[0-9A-F-]{44}")) {
  // do action
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!