#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Can Regular Expression insert values?


    Can regular expression insert values rather than just capturing values?

    For example,
    I wrote a regular expression to capture "1234" from the name "abcd.1234.abcd.com"

    However, I want it to say "s1234"

    Is there any way to have regular expression insert the "s" in front of "1234"?

    Any advice is very much appreciated.
    Thanks,
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,296
    Rep Power
    9400
    Use your regex in a find/replace, and replace the $1=1234 that was matched with s$1.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0
    $string = "abcd.1234.abcd.com";
    $string = preg_replace("/\.(\d+)\./ism",".s$1.",$string);

    i was test at php.toolregex.com
    it result abcd.s1234.abcd.com

IMN logo majestic logo threadwatch logo seochat tools logo