Regular expressions: Difference between revisions

Content added Content deleted
({{omit from|PARI/GP}})
Line 626: Line 626:
=={{header|PHP}}==
=={{header|PHP}}==
{{works with|PHP|5.2.0}}
{{works with|PHP|5.2.0}}
<lang php> $string = 'I am a string';</lang>
<lang php>$string = 'I am a string';
# Test

if (preg_match('/string$/', $string))
Test

<lang php>if (preg_match('/string$/', $string))
{
{
echo "Ends with 'string'\n";
echo "Ends with 'string'\n";
}
}</lang>
# Replace
$string = preg_replace('/\ba\b/', 'another', $string);
echo "Found 'a' and replace it with 'another', resulting in this string: $string\n";</lang>


Output:
Replace
<pre>Ends with 'string'

Foud 'a' and replaced it with 'another', resulting in this string: I am another string</pre>
<lang php>$string = preg_replace('/\ba\b/', 'another', $string);
echo "Found 'a' and replace it with 'another', resulting in this string: $string\n";</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==