Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   find two halves of a word? (http://www.velocityreviews.com/forums/t887560-find-two-halves-of-a-word.html)

Ken Sington 08-08-2004 06:38 AM

find two halves of a word?
 
is it possible to find a word that's broken?

if:
$str="hel
lo larry";
# that is, "hel" + "\n" line break + "lo larry"

and I want to find "hello" in that string.
is that possible?

or better yet:
$str = "hel$^%&*&*&lo larry";

gnari 08-08-2004 09:29 AM

Re: find two halves of a word?
 
"Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
news:q4-dnSZmSpjkV4jcRVn-iQ@speakeasy.net...
> is it possible to find a word that's broken?
>
> if:
> $str="hel
> lo larry";
> # that is, "hel" + "\n" line break + "lo larry"
>
> and I want to find "hello" in that string.
> is that possible?


just remove the newline before matching
my ($str2=$str)=~s/\n//g;
print "Match!\n" if $str2=~/hello/;

>
> or better yet:
> $str = "hel$^%&*&*&lo larry";


this might not contain what you think
assuming you meant
$str = 'hel$^%&*&*&lo larry';
and that $str = '$^%&*&*&' is a fixed string that you
want to ignore:
my $ign='$^%&*&*&';
my ($str2=$str)=~s/\Q$ign\E//g;
print "Match!\n" if $str2=~/hello/;

gnari





All times are GMT. The time now is 12:17 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.