Regular expressions: Difference between revisions

({{omit from|PARI/GP}})
Line 626:
=={{header|PHP}}==
{{works with|PHP|5.2.0}}
<lang php> $string = 'I am a string';</lang>
# Test
 
<lang php>if (preg_match('/string$/', $string))
Test
 
<lang php>if (preg_match('/string$/', $string))
{
echo "Ends with 'string'\n";
}
}</lang>
# Replace
<lang php>$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}}==