Professional Web Applications Themes

Regexp problem - PERL Beginners

Hi all, (Example 1) I have the following lines: This is some text....<B luebird>..MBAAAEgAAAQAB blaah,blaah =+=+=+=+=+=+=+=+=+=+=+ (Example 2) but sometimes it looks like this: This is some text....<Bluebird>.. MBAAAEgAAAQAoBAAAQKAREDSCETRTBDFS blaah,blaah =+=+=+=+=+=+=+=+=+=+=+ Now, given this, I am wanting to skip over the text when I find it (bounded by <Bluebird> and =+=+=+) So, I have a loop as follows: LINE: while ( <> ) { next LINE if (m/\.{4}<B.*ird>/s .. /(\+\=\+)$/); print; } The "next" works fine if the <Bluebird> tag is not split as in example (2) above, but fails when the <Bluebird> tag is split as in example (1) ...

  1. #1

    Default Regexp problem

    Hi all,

    (Example 1)
    I have the following lines:
    This is some text....<B
    luebird>..MBAAAEgAAAQAB
    blaah,blaah
    =+=+=+=+=+=+=+=+=+=+=+

    (Example 2)
    but sometimes it looks like this:
    This is some text....<Bluebird>..
    MBAAAEgAAAQAoBAAAQKAREDSCETRTBDFS
    blaah,blaah
    =+=+=+=+=+=+=+=+=+=+=+

    Now, given this, I am wanting to skip over the text when I find it
    (bounded by <Bluebird> and =+=+=+)

    So, I have a loop as follows:
    LINE: while ( <> ) {
    next LINE if (m/\.{4}<B.*ird>/s .. /(\+\=\+)$/);
    print;
    }

    The "next" works fine if the <Bluebird> tag is not split as in example
    (2) above, but fails when the <Bluebird> tag is split as in example (1)
    above.

    Can anyone show me what I am doing wrong.

    Thanks
    H
    --
    -o)
    /\\ Message void if penguin violated
    _\_V Don't mess with the penguin

    Hamish Whittal South Africa
    082 803 5533 021 671 7710

    Hamish Guest

  2. #2

    Default Re: Regexp problem

    Hamish Whittal wrote: 

    Hard to tell, since you didn't post a complete program + sample data
    that illustrates your problem. Can it possibly be that you need to
    make the first regex non-greedy?

    /\.{4}<B.*?ird>/s
    --------------^

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

  3. #3

    Default Re: Regexp problem

    Gunnar Hjalmarsson wrote: 

    Or a more plausible explanation is that you are looping over the text
    line by line. Maybe you simply need to do:

    my $text = do { local $/; <> };
    $text =~ s/[^\n]*\.{4}<B.*?ird>.*?\+=\+\n//gs;
    print $text;

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Guest

Similar Threads

  1. using regexp to substitute - problem
    By Radhika in forum PERL Beginners
    Replies: 2
    Last Post: August 6th, 08:52 PM
  2. Metacharacter problem in regexp
    By Petri in forum PERL Beginners
    Replies: 6
    Last Post: March 7th, 08:46 PM
  3. regexp splitting problem
    By Brett in forum Ruby
    Replies: 4
    Last Post: December 3rd, 01:17 AM
  4. regexp problem
    By Taylor York in forum PHP Development
    Replies: 14
    Last Post: October 17th, 03:11 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139