Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    glz
    glz is offline
    New Coder
    Join Date
    Apr 2007
    Posts
    57
    Thanks
    3
    Thanked 0 Times in 0 Posts

    ajax preg regex tester Live tester!, sharing a online app I made

    Short & Sweet little app I made with PHP and ajax to test regex patterns in real time, without pressing the submit. I am using regular expressions a lot lately in PHP for something I am developing. An app like this speeds up my dev time with necessary testing. Most of the regex testers online that I found didn't work live and so I made my own. smile.gif

    Example of use:
    Paste this in for regex:
    ~(abc)~i

    paste this in for haystack:
    lalal jksdfio abcder yah lalala
    ABC can you count to 3?

    Array[0] is the pattern match
    Array[1-..] are the substring matches

    http://nancywalshee03.freehostia.com...gex_tester.php


    -Enjoy!

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by glz View Post
    Most of the regex testers online that I found didn't work live and so I made my own. smile.gif
    Regex:
    /^[0-9]+(\.[0-9]+)+/

    Haystack:

    Match:
    Code:
    Array
    (
        [0] => Array
            (
            )
    
        [1] => Array
            (
            )
    
    )
    best regards

  • #3
    glz
    glz is offline
    New Coder
    Join Date
    Apr 2007
    Posts
    57
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    Regex:
    /^[0-9]+(\.[0-9]+)+/

    Haystack:

    Match:
    Code:
    Array
    (
        [0] => Array
            (
            )
    
        [1] => Array
            (
            )
    
    )
    best regards
    What was the point of your reply? The haystack you supplied was empty, so of course there are no matches. If you were trying to tell me something, I did not understand. If so, explicate what you're trying to tell me a little more.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by glz View Post
    What was the point of your reply? The haystack you supplied was empty, so of course there are no matches. If you were trying to tell me something, I did not understand. If so, explicate what you're trying to tell me a little more.
    inside match textbox is a piece of your php code!

    best regards

  • #5
    glz
    glz is offline
    New Coder
    Join Date
    Apr 2007
    Posts
    57
    Thanks
    3
    Thanked 0 Times in 0 Posts
    still don't quite understand what you're saying, you mean that the matches box looks like a printed php array? yes, purposely so.

    However I did notice a problem though its with the + symbols. As you know + signs are url encoded space characters. I am using encodeURI() function in in JS to encode the posted data as you can see in my source. However, it is not encoding the + symbols and sending them as they are, which the PHP is then of course decoding as spaces. Is there a better url encode function for JS that I can use that will encode + signs as %2B as its supposed to?

    Finding a better function to url encode the data via JS is the only solution I can think of, if you have a better idea let me know.

    *edit
    Escape() also does not encode the + sign

    *edit I just found out about encodeURIComponent() function, it does properly encode the + chars, if there is a better solution or reason for not using this, let me know.
    Last edited by glz; 12-17-2007 at 07:08 AM.

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by glz View Post
    still don't quite understand what you're saying, you mean that the matches box looks like a printed php array? yes, purposely so.
    NO, I SAY THAT I CUT & PASTE THIS CODE FROM YOUR TEXTBOX

    Quote Originally Posted by glz View Post
    However I did notice a problem though its with the + symbols. As you know + signs are url encoded space characters. I am using encodeURI() function in in JS to encode the posted data as you can see in my source.
    I can't see your source, php is server side, this if you don't show me like above,

    Quote Originally Posted by glz View Post
    However, it is not encoding the + symbols and sending them as they are, which the PHP is then of course decoding as spaces. Is there a better url encode function for JS that I can use that will encode + signs as %2B as its supposed to?

    Finding a better function to url encode the data via JS is the only solution I can think of, if you have a better idea let me know.
    some people used to disable js, me for example, but this is my problem, yours is to put a "don't work if you have js disabled".
    Anyway I don't know other ways to make this work without js and submit.

    Try to reproduce the error:
    step 1. Type '^' => will show in 'match' textbox a error message, "missing /" is normal I presume
    step 2. Type "/" => show the code
    step ....: edit regex => still show the code

    I hope this help

    best regards
    Last edited by oesxyl; 12-17-2007 at 07:41 AM.

  • #7
    glz
    glz is offline
    New Coder
    Join Date
    Apr 2007
    Posts
    57
    Thanks
    3
    Thanked 0 Times in 0 Posts
    some people used to disable js, me for example, but this is my problem, yours is to put a "don't work if you have js disabled".
    Anyway I don't know other ways to make this work without js and submit.
    ah why didn't you just say so then?? I can't read your mind.
    Don't you know that ajax involves javascript, that you need javascript enabled was a given.

    I can't see your source, php is server side, this if you don't show me like above,
    I was talking about the javascript/html source, which you can see.
    I thought this was obvious as I was referring to a JS problem I was having.
    Since when did outputting an array mean that you're showing your PHP source? Sure I might add highlighting the actual substring and pattern in the haystack later, but seeing the array of matches was more beneficial to me and I'm sure to others who would like to test preg flavor regex in PHP.

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by glz View Post
    ah why didn't you just say so then?? I can't read your mind.
    Don't you know that ajax involves javascript, that you need javascript enabled was a given.
    my replay has nothing to do with that, I enable js,
    the problem was after and I try to describe some steps in my previous post( editi the post when I figure out that you don't have enough information for debugging)

    Quote Originally Posted by glz View Post
    I was talking about the javascript/html source, which you can see.
    I thought this was obvious as I was referring to a JS problem I was having.
    Since when did outputting an array mean that you're showing your PHP source? Sure I might add highlighting the actual substring and pattern in the haystack later, but seeing the array of matches was more beneficial to me and I'm sure to others who would like to test preg flavor regex in PHP.
    ok, in that case if a future not a bug,

    best regards

  • #9
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Here's an urlencode function that looks good


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •