+ Reply to Thread
Results 1 to 3 of 3

Thread: Help with Regex

  1. #1
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Help with Regex

    hi

    I have this regular expression in php using preg_replace...
    PHP Code:

    preg_match
    ("/\"\w+\"\.z\(\)/"$string$matches); 
    anyway to keep it short it matches...

    "This is a string".z()

    and

    "Another string".z()

    but it unfortunately matches...

    "GET: "http://this.url.com/".z()

    when I want it to only match "http://this.url.com/".z();

    I am new to creating my own regex and want to resort to
    doing
    \"[a-zA-Z0-9\D]*\"\.z\(\)

    or is there a better way...

    My objective is to create a regex that matches a string enclosed within double quotes followed that is passed to a function z() in javascript. The source string is also pre-processed to replace any escaped quotes inside the string.
    Don't get me wrong as I believe if and when I help someone I also help myself whereby whatever someone learns I also learn.

    But I will also accept credits or reps if you really want to part with it.

  2. #2
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: Help with Regex

    How about:

    PHP Code:
    function getData(){
    if(
    $_GET['somevar'] == $yourRegEx){
    //do something

    else{
    //do something else
    }
    }
    getData(); 
    Or did I completely misinterpret what you are asking? Lol. It's 1:00 am. So, it's completely possible.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  3. #3
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Help with Regex

    i think you want:

    "/"http[.*]/.z()/""

    match any strings that start with "http with 0 or more characters to .z()"

    it is frowned upon to use .*, but I think in this case it is the simplest way to do this. If you know the URL is only going to be http://example.com or http://mysite.com and not http://forum.othersite.com/someting/...=23513214;save you can probably use [a-zA-Z0-9_/.//]+ which should match one or more alphanumeric, underscore, forward slash, or period characters.

    I'm new to regex, so I can't guarantee this will work, but it looks right to me :P
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

+ Reply to Thread

Similar Threads

  1. a little javascript regex help
    By MasterMax1313 in forum Programming Help
    Replies: 2
    Last Post: 05-02-2008, 09:00 AM
  2. cURL Login And Cookies and Regex
    By Tau_Zero in forum Programming Help
    Replies: 4
    Last Post: 12-12-2007, 12:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers