Regular expressions: Difference between revisions

Content added Content deleted
m (first java example)
m (→‎[[Java]]: substitute)
Line 16: Line 16:
}
}


Substitute

String orig = "I am the original string";
Pattern pat = Pattern.compile("original"); // match "original"
Matcher mat = pat.matcher(orig); // get the Matcher

String result = mat.replaceAll("modified"); // replace all matches against the pattern with "modified"
// result is now "I am the modified string"


==[[Perl]]==
==[[Perl]]==