RE: Regex

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nitsan,

 

Not a problem, thanks for the help. So, it is printed as ^Z. However, I
created a little test.php script to accept input and print it back to
me. So, I used control z as my test, and it simply printed a line, and
that's all. So, then I input control z, and then had it print a letter
right after ("a"), and it was just the letter a. no whitespace, no
breaks, nothing. 

 

I even tried one more thing: in the loop (not in the code below) I put
unset($choice), right above where it tells the user their input is
invalid and asks for it again. Even this did not change anything: when
pressing control - z, it looped infinitely.

 

I assumed that \c would be the regex to mend this, as the php manual has
this as "control-x, where x is any character". I even tried every
variation of this, with a key combination like \cZ, or \cz, or \c[zZ],
yet it still does not catch it.

 

 

 

 

Thanks,

 

Jesse Hazen

 

________________________________

From: nitsan@xxxxxxxxxxxx [mailto:nitsan@xxxxxxxxxxxx] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 2:09 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Regex

 

If you can point me on the character which control-z creates it would
make it easier, I have no idea of it ;)

I'm sorry mate.

On Thu, Mar 26, 2009 at 11:06 PM, <Jesse.Hazen@xxxxxxxxxxxxx> wrote:

Nitsan,

 

Thanks again. Sad to say, same result.

 

The second option looped an error: Warning: preg_replace(): Compilation
failed: nothing to repeat at offset 17 

 

 

 

 

Thanks,

 

Jesse Hazen

________________________________

From: nitsan@xxxxxxxxxxxx [mailto:nitsan@xxxxxxxxxxxx] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:58 PM


To: Hazen, Jesse, arvato digital services llc
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Regex

 

I have no idea about this control-Z thing, you might want to try it with
UTF (just add the 'u' modificator):
$str = preg_replace("#[^a-zA-Z0-9]+#uis", "", $str);

Or try this:
$str = preg_replace("#(\b[^a-zA-Z0-9]\b?)+#uis", "", $str);

I may be wrong about the second one but it might work...

On Thu, Mar 26, 2009 at 10:51 PM, <Jesse.Hazen@xxxxxxxxxxxxx> wrote:

Nitsan,

 

Thank you very much for the input. However, I just gave this a try and
it still did not strip the control-Z. Therefore, it is still hitting my
loop later and looping infinitely. I am sure I could mend that by
working something into that loop, but there are several loops I would
need to do this on. If I can stop the command at this method, then the
entire script will run perfectly.

 

 

 

 

Thanks,

 

Jesse Hazen

_________________ 

arvato digital services llc

A Bertelsmann Company

29011 Commerce Center Dr.

Valencia, CA 91355

 

http://arvatodigitalservices.com

 

jesse.hazen@xxxxxxxxxxxxx

Tel. +1 (661) 702-2727

Fax. +1 (661) 775-6478

________________________________

From: nitsan@xxxxxxxxxxxx [mailto:nitsan@xxxxxxxxxxxx] On Behalf Of
Nitsan Bin-Nun
Sent: Thursday, March 26, 2009 1:44 PM
To: Hazen, Jesse, arvato digital services llc
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Regex

 

To filter out everything which is not A-Z, a-z and 0-9 try this regex:

$str = preg_replace("#[^a-zA-Z0-9]+#is", "", $str);

On Thu, Mar 26, 2009 at 10:23 PM, <Jesse.Hazen@xxxxxxxxxxxxx> wrote:

Hi,



Brand new to regex. So I have a cli which runs a regex on users input,
to make sure that only 0-9 and A-Z are accepted. It should strip
everything else. My problem is that when you press control-Z (on
Windows; I have not yet tested this on linux, and I will, but I would
like this to be compatible with both OS's) it loops infinitely saying
invalid data (because of the next method call, which decides what to do
based on your input). So, here is the input code. Is there a way I can
ensure that control commands are stripped, here?











           public function getSelection() {



                       $choice =
$this->validateChoice(trim(strtoupper(fgets(STDIN))));

                       return $choice;



           }



           private function validateChoice($choice) {



                       $choice =
ereg_replace("/[^0-9A-Z]/","",$choice);

                       return $choice;



           }







I have tried a ton of different things to try and fix this. Tried
/\c.|[^0-9A-Z]/, and many variations of \c and the [^0-9A-Z], to no
avail. I also tried using both preg_replace() as well as ereg_replace().
I spent a lot of time on the regex section of the PHP manual, but I am
not finding anything. Any advise on how to accomplish this?







Thanks,



Jesse Hazen

 

 

 


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux