...

View Full Version : ajax preg regex tester Live tester!, sharing a online app I made



glz
12-16-2007, 07:52 PM
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/regextester/regex_tester.php


-Enjoy!

oesxyl
12-17-2007, 04:39 AM
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:


Array
(
[0] => Array
(
)

[1] => Array
(
)

)


best regards

glz
12-17-2007, 05:28 AM
Regex:
/^[0-9]+(\.[0-9]+)+/

Haystack:

Match:


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.

oesxyl
12-17-2007, 05:45 AM
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

glz
12-17-2007, 05:56 AM
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.

oesxyl
12-17-2007, 06:13 AM
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



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, :D


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

glz
12-17-2007, 06:35 AM
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.

oesxyl
12-17-2007, 07:10 AM
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)


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, :D

best regards

Mwnciau
12-17-2007, 09:02 AM
Here (http://cass-hacks.com/articles/code/js_url_encode_decode/)'s an urlencode function that looks good



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum