Click here to get back home

different regexp result

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
different regexp result Petr Vileta 02-10-2008
Get Chitika Premium
Posted by Petr Vileta on February 10, 2008, 8:21 pm
Please log in for more thread options
I have Perl 5.6.1 installed and I use Komodo 3.5 which internaly use Perl 5.8
( I don't know subversion). In Komodo IDE is Regexp Toolkit to test regular
expressions.

When I test this
$x = 'a b c d e f 123';
$x =~s/(\b)\s(\S)/$1$2/g;
print $x;

in Komodo Regexp Tool then I get

abcdef 123

But when I test the same in Perl 5.6.1 then I get

ab cd ef 123

I found a workaround for Perl 5.6.1

1 while($x =~s/(\b)\s(\S)/$1$2/g);

but ... :-) Please can anybody explain me what is wrong?

P.S. Please, don't tell me "Upgrade to perl 5.8/5.10" - I can't.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail from
another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>


Posted by Uri Guttman on February 10, 2008, 8:56 pm
Please log in for more thread options

PV> I have Perl 5.6.1 installed and I use Komodo 3.5 which internaly use
PV> Perl 5.8 ( I don't know subversion). In Komodo IDE is Regexp Toolkit
PV> to test regular expressions.

PV> When I test this
PV> $x = 'a b c d e f 123';
PV> $x =~s/(\b)\s(\S)/$1$2/g;

that (\b) makes no sense as a word boundary is a zero width assertion
and grabbing that will either be a null string or possibly undef. also
you have the boundary at the beginning where it is always true as the
first char of data is on a word boundary to its left.

PV> in Komodo Regexp Tool then I get

PV> abcdef 123

and if you explain your goal in english and not just with an example of
output you will get better answers. there are several ways to get this
sort of result.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

Posted by Petr Vileta on February 11, 2008, 1:06 am
Please log in for more thread options
Uri Guttman wrote:
>
>> I have Perl 5.6.1 installed and I use Komodo 3.5 which internaly use
>> Perl 5.8 ( I don't know subversion). In Komodo IDE is Regexp Toolkit
>> to test regular expressions.
>
>> abcdef 123
>
> and if you explain your goal in english and not just with an example
> of output you will get better answers. there are several ways to get
> this sort of result.
>
OK, I try to explain my goal using my poor english ;-)
I have string (e.g. street name, human name etc.) and some stupid people are
used to put space after aech single character to accentuate this words. I want
to store these string to database but I can tidy-up unnecessary spaces. From:

a b c d e f 123

I deend to get

abcdef 123

In original string where no space should be there is 1 space and where 1 space
should be there are 2 or more spaces.
What is the right regexp to do it in 1 step?
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)

Please reply to <petr AT practisoft DOT cz>


Posted by Florian Kaufmann on February 11, 2008, 2:15 am
Please log in for more thread options
> used to put space after aech single character to accentuate this words. I want
> to store these string to database but I can tidy-up unnecessary spaces. From:

I can think of two alternatives, both of which are untested

$x = ($x =~ tr/ \t/ /s); # alternative 1
$x = ($x =~ s/\s+/ /g); # alternative 2

Greetings

Flo

Posted by Uri Guttman on February 11, 2008, 2:42 am
Please log in for more thread options

>> used to put space after aech single character to accentuate this words. I
want
>> to store these string to database but I can tidy-up unnecessary spaces.
From:

FK> I can think of two alternatives, both of which are untested

FK> $x = ($x =~ tr/ \t/ /s); # alternative 1

that squeezes multiple space/tabs to single spaces. he wants to delete
single spaces and only squeeze multiples to 1 space

FK> $x = ($x =~ s/\s+/ /g); # alternative 2

that does the same as your previous answer but slower

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

Similar ThreadsPosted
really strange mysql result March 14, 2005, 3:13 pm
reading a file to the end regardless of result January 15, 2006, 4:40 pm
same code diff result July 28, 2006, 4:29 pm
How can I use wget to get the result of jsp page April 17, 2007, 10:25 pm
using the result of a variable regular expression August 26, 2004, 10:19 am
Re: using the result of a variable regular expression August 26, 2004, 10:56 am
Re: using the result of a variable regular expression August 26, 2004, 11:53 am
Unexpected Result From Pipe Read February 15, 2005, 12:01 am
mod_perl 1.29: send_fh(): result status? August 24, 2005, 12:31 pm
read image file - and process the result December 4, 2004, 4:01 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap