Regular expressions: Difference between revisions

m
m (→‎{{header|PHP}}: lang tag)
Line 396:
=={{header|PHP}}==
{{works with|PHP|5.2.0}}
<lang php> $string = 'I am a string';</lang>
 
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>
 
=={{header|Python}}==