Click to See Complete Forum and Search --> : Help with Regular expression


ezryder
05-07-2005, 05:50 AM
I have some code:

$logtext = "Inone4u: folds
Returned uncalled bets 670 to jumbo60
jumbo60: doesn't show hand";

($scrap, $ST_uncalledbets,$ST_returnedto) = ($logtext =~ /(.*)Returned uncalled bets (\d+) to (\w+)/);

What I then do is I use the variable $ST_returnedto to compare to another variable which also holds the value "jumbo60"

All of the above works fine. However I need the code to handle a value for $ST_returnedto which includes spaces (e.g. jumbo60 might be jumbo 60)

So I have modified my RE to:

($scrap, $ST_uncalledbets,$ST_returnedto) = ($logtext =~ /(.*)Returned uncalled bets (\d+) to (.*)/);

If I run this script the variable $ST_returnedto seems to be populated correctly but if I then compare $ST_returnedto to the other variable which also holds the value "jumbo60" the result is that they are not equal.

I dont understand why. Can anyone help please?

Thanks in advance.

Jeff Mott
05-07-2005, 01:18 PM
By default the . pattern does not match a newline, so that match should stop at the end of the line. Either it's not working like that for some reason, or there is something more at the end of the line.

Can you print out the value of $ST_returnedto to see exactly what it is that is being matched?

ezryder
05-07-2005, 03:10 PM
Thanks for the reply. I have printed the value out and it is exactly as I expected. I have even tried chomp to take any newlines of both variables so I am sure it is not a new line which is the problem.

:confused:

Jeff Mott
05-07-2005, 06:31 PM
I need the code to handle a value for $ST_returnedto which includes spaces (e.g. jumbo60 might be jumbo 60) ... but if I then compare $ST_returnedto to the other variable which also holds the value "jumbo60" the result is that they are not equalDo you account for the space? Or are you ultimately trying to compare "jumbo 60" eq "jumbo60"?

ezryder
05-08-2005, 05:51 AM
I'm not trying to compare "jumbo 60" eq "jumbo60".

What I am saying is the line I posted has jumbo60 as the name. If I use (\w+) to recognise this my script works fine. however if I use (.*) whilst the name sems to be picked up correctly (if I look at it printed out) the comparison doesn't work.

My problem is I need to use (.*) because my script has to work in the case of a file where jumbo60 contains spaces, e.g. it is "jumbo 60" or say "jum bo"

So I agree, it is like some trailing space or newline is being picked up but even if I chomp the values they still dont compare as being equal.

Thanks.

Jeff Mott
05-08-2005, 09:59 AM
Make sure your script is being uploaded as text or ASCII rather than binary. Since Windows machines use \r\n as a newline whereas Unix uses only \n, your match may be including the \r character.

ezryder
05-08-2005, 10:34 AM
Thats done the trick!

thanks for your help and persistence!

:D