Regular expressions: Difference between revisions

Line 431:
 
=={{header|Java}}==
{{works with|Java|1.54+}}
Test
 
Line 437:
if (str.matches(".*string")) { // note: matches() tests if the entire string is a match
System.out.println("ends with 'string'");
}</lang>
 
To match part of a string, or to process matches:
<lang java>import java.util.regex.*;
Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher(str);
while (m.find()) {
// use m.group() to extract matches
}</lang>
 
Anonymous user