Regular expressions: Difference between revisions
Content added Content deleted
(Frink) |
(Updated D entry) |
||
Line 376: | Line 376: | ||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>import std.stdio, std. |
<lang d>import std.stdio, std.regex; |
||
void main() { |
void main() { |
||
string s = "I am a string"; |
immutable string s = "I am a string"; |
||
// Test: |
// Test: |
||
if ( |
if (!match(s, r"string$").empty) |
||
writeln("Ends with 'string'."); |
|||
// Test, storing the regular expression: |
|||
auto re1 = RegExp(r"string$"); |
|||
if (re1.search(s).test) |
|||
⚫ | |||
// Substitute: |
// Substitute: |
||
replace(s, regex(" a "), " another ").writeln(); |
|||
// Substitute, storing the regular expression: |
|||
auto re2 = RegExp(" a "); |
|||
writefln(re2.replace(s, " another ")); |
|||
}</lang> |
}</lang> |
||
{{out}} |
|||
⚫ | |||
⚫ | |||
I am another string</pre> |
|||
⚫ | |||
=={{header|Erlang}}== |
=={{header|Erlang}}== |