List Info

Thread: Regex whitespace and non-word puzzler




Regex whitespace and non-word puzzler
user name
2007-01-30 15:47:37
I want to be able prefix all non-words EXCEPT SPACES with a
backslash.

I would like to make this 3 line regex substitution into a
single 
line - avoiding the temporary whitespace substitution.

Any help will be appreciated

NJH

#######
#! perl 
use strict;
use warnings;
use diagnostics;

my $text = 'A ver~sion, of 5 6  NJH's SD card 'which'
enables the 
PCB itself to be plug'ged (directly) into a
#,standard SD card 
input connector';

$text =~ s/(s+)/zxz/g;
$text =~ s/(W+)/\$1/g;
$text =~ s/(zxz)/ /g;

print $text;
#######

Results with this:

A ver~sion, of 5 6 NJH's SD card 'which' enables the
PCB itself 
to be plug'ged (directly) into a #,standard SD card
input 
connector




Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: Regex whitespace and non-word puzzler
user name
2007-01-30 15:55:44
>>>>> "hooyar66" == hooyar66 
<pcbcadhotpop.com> writes:

hooyar66> I want to be able prefix all non-words EXCEPT
SPACES with a backslash.

you mean non-word-characters?

so the set of W without space?

That'd be [^w ], so s/([^w ])/\$1/g

Pretty simple, once you understand set arithmetic. 


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. -
+1 503 777 0095
<merlynstonehenge.com> <URL:http://www.ston
ehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy,
etc. etc.
See PerlTraining.Stonehenge.com for onsite and
open-enrollment Perl training!


Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )