Thread: Regex

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

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    I need some help with making a regular expression to search a string for a character (a frontslash) and replace it with another character (a backslash).

    Would this be any different from search/replacing a letter or number?

    Thanks,
    Mike
  2. #2
  3. No Profile Picture
    The Dude Abides
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2000
    Location
    grass valley,ca
    Posts
    1,062
    Rep Power
    16
    Try this
    <?
    $string = "This is a test";
    $replacement = ' /';
    echo ereg_replace (" is", $replacement, $string);
    ?>
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Norcross, GA
    Posts
    458
    Rep Power
    14
    I had to add an extra backslash in $replacement, but it works like a charm!

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $string = "C:/test/test.html";
    $replacement = '';
    echo ereg_replace ("/", $replacement, $string);
    [/code]

    Thanks for the tip.

    Mike

Similar Threads

  1. compile php to use system regex and apache2
    By edman007 in forum PHP Development
    Replies: 0
    Last Post: November 7th, 2003, 07:11 PM
  2. improve my regex
    By JunkCookie in forum Perl Programming
    Replies: 7
    Last Post: September 29th, 2003, 12:52 PM
  3. Need help on regex?
    By trendmatrix in forum HTML Programming
    Replies: 1
    Last Post: August 2nd, 2003, 04:54 PM
  4. Replies: 1
    Last Post: October 30th, 2001, 11:42 AM
  5. which regex approach is best
    By bumperbox in forum Perl Programming
    Replies: 3
    Last Post: August 30th, 2001, 05:05 PM

IMN logo majestic logo threadwatch logo seochat tools logo