Skip to content

Instantly share code, notes, and snippets.

@madr
Last active January 21, 2016 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madr/6460b808af830b7c0523 to your computer and use it in GitHub Desktop.
Save madr/6460b808af830b7c0523 to your computer and use it in GitHub Desktop.
String replacement using regular expressions
var results = 'hi bob123';
results = results.replace(/bob\d+/, 'cooper');
<?php
$results = 'hi bob123';
$results = preg_replace('/bob\d+/', 'cooper', $results);
import re
results = 'hi bob123'
results = re.sub('bob\d+', 'cooper', results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment