find two halves of a word?

K

Ken Sington

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";
 
G

gnari

Ken Sington said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top