javaregex

get matches words by regex java


I need a method for getting whole word if matches a pattern, for exemple:

<p>This is some text. <img src="md5_id=12345" </p>

I'll need to get md5_id=12345, so pattern will be smth like :...md5_id:xxxxx... where x can be 0-9 or a-z/A-Z


Solution

  • I got the solution...

        private void method(String txt) {
        Pattern pattern = Pattern.compile(("md5_id=[a-zA-Z_0-9]{5,}"));
    
        Matcher m = pattern.matcher(txt);
        while (m.find()) {
            Log.d("log", m.group());
    
        }
    }