Regular expressions: Difference between revisions

Content added Content deleted
m (→‎{{header|Java}}: lang tag)
Line 295: Line 295:
Test
Test


String str = "I am a string";
<lang java> String str = "I am a string";
if (str.matches(".*string$")) {
if (str.matches(".*string$")) {
System.out.println("ends with 'string'");
System.out.println("ends with 'string'");
}
}</lang>


Substitute
Substitute


String orig = "I am the original string";
<lang java> String orig = "I am the original string";
String result = orig.replaceAll("original", "modified");
String result = orig.replaceAll("original", "modified");
// result is now "I am the modified string"
// result is now "I am the modified string"</lang>


=={{header|JavaScript}}==
=={{header|JavaScript}}==