Regular expressions: Difference between revisions

Content added Content deleted
m (Changed over to headers)
Line 64: Line 64:
std::cout << dest_string << std::endl;
std::cout << dest_string << std::endl;
}
}


=={{header|D}}==
import std.stdio, std.regexp;

void main() {
string s = "I am a string";

// Test:
if (search(s, r"string$"))
writefln("Ends with 'string'");

// Test, storing the regular expression:
auto re1 = RegExp(r"string$");
if (re1.search(s).test)
writefln("Ends with 'string'");

// Substitute:
writefln(sub(s, " a ", " another "));

// Substitute, storing the regular expression:
auto re2 = RegExp(" a ");
writefln(re2.replace(s, " another "));
}

Note that in std.string there are string functions to perform those string operations in a faster way.


=={{header|Java}}==
=={{header|Java}}==