find two halves of a word?

Discussion in 'Perl Misc' started by Ken Sington, Aug 8, 2004.

  1. Ken Sington

    Ken Sington Guest

    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";
     
    Ken Sington, Aug 8, 2004
    #1
    1. Advertising

  2. Ken Sington

    gnari Guest

    "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
    news:...
    > 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
     
    gnari, Aug 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GenxLogic
    Replies:
    3
    Views:
    1,370
    andrewmcdonagh
    Dec 6, 2006
  2. Frost
    Replies:
    8
    Views:
    543
    Vladimir S. Oka
    Feb 10, 2006
  3. Replies:
    8
    Views:
    373
  4. Wybo Dekker
    Replies:
    1
    Views:
    395
    Yukihiro Matsumoto
    Nov 15, 2005
  5. Mohit Sindhwani
    Replies:
    5
    Views:
    212
    Mohit Sindhwani
    Oct 27, 2008
Loading...

Share This Page