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

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Regex Newbie in need of assistance


    Hello everyone,

    Im new to regex programming and been toying with RegExr for some time and im stuck with a problem.

    For example,
    /search?q=related:wwwdotspeedtestdotcom/+test&tbo=1

    I would need to do a regex replace to remove
    "/search?q=related:" and "/+test&tbo=1"
    and just get wwwdotspeedtestdotcom as result.

    Taking into factor that "/search?q=related:" and "/+test&tbo=1" are constants, and i got a list of urls i need to extract, what regex expressions should i be using to remove these 2 constant?

    Im only able to extract it out via (www.)+?[a-zA-Z0-9_,:]+(.com/)?(.net)? but its not the kind of expression i wanted.

    Any help would be deeply and greatly appreciated!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    831
    Rep Power
    496
    Maybe you could try to do a replace of:

    Code:
    /\/search\?q=related:/
    and

    Code:
    /\/\+test&t/
    with nothing.
  4. #3
  5. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,056
    Rep Power
    9398
    Originally Posted by stingray91
    Taking into factor that "/search?q=related:" and "/+test&tbo=1" are constants,
    You know the exact prefix and suffix of the string you want?

    Grab a substring starting at character 19 (offset 18) and going up to the 17th-to-last character (offset -16). Using PHP as an example,
    PHP Code:
    $string "/search?q=related:wwwdotspeedtestdotcom/+test&tbo=1";
    echo 
    substr($string18, -16); 

IMN logo majestic logo threadwatch logo seochat tools logo