Simple question

Discussion in 'Perl Misc' started by Barty Slartfast, Feb 11, 2004.

  1. I have a string of which the middle part is an unknown generated by user
    input, for example:

    ladiddfa BEGIN balblabla END and whatever else..."

    The middle part being --> balblabla <---

    I would like to extract whatever string is within the BEGIN and END
    delimiters, but I don't know in advance what the middle part is.
    It may be any number of characters, numbers, empty spaces, linebreaks, or
    nothing at all.
    Any idea of the simplest possible perl code to do this?
    Barty Slartfast, Feb 11, 2004
    #1
    1. Advertising

  2. In article <c0dv81$hq4$04$-online.com>,
    Barty Slartfast <> wrote:
    :I have a string of which the middle part is an unknown generated by user
    :input, for example:

    :ladiddfa BEGIN balblabla END and whatever else..."

    :The middle part being --> balblabla <---

    :I would like to extract whatever string is within the BEGIN and END
    :delimiters, but I don't know in advance what the middle part is.
    :It may be any number of characters, numbers, empty spaces, linebreaks, or
    :nothing at all.
    :Any idea of the simplest possible perl code to do this?

    if ( m/BEGIN\s(.*?)\sEND/s ) {
    $middle = $1;
    } else {
    ???
    }
    --
    Strange but true: there are entire WWW pages devoted to listing
    programs designed to obfuscate HTML.
    Walter Roberson, Feb 11, 2004
    #2
    1. Advertising

  3. Barty Slartfast <> wrote:

    > Subject: Simple question


    Too simple Subject.


    Please put the subject of your article in the Subject of your article.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 11, 2004
    #3
  4. Barty Slartfast

    Tore Aursand Guest

    On Wed, 11 Feb 2004 20:22:03 +0000, Walter Roberson wrote:
    >> ladiddfa BEGIN balblabla END and whatever else..."
    >>
    >> The middle part being --> balblabla <---
    >>
    >> I would like to extract whatever string is within the BEGIN and END
    >> delimiters, but I don't know in advance what the middle part is. It may
    >> be any number of characters, numbers, empty spaces, linebreaks, or
    >> nothing at all.


    > if ( m/BEGIN\s(.*?)\sEND/s ) {
    > $middle = $1;
    > } else {
    > ???
    > }


    Better yet, IMO;

    if ( m,BEGIN\s*(.*?)\s*END,s ) {
    my $middle = $1;
    }
    else {
    # No match
    }

    Just from the top of my head, but I'm sure that the OP don't want any
    extra spaces. :)



    --
    Tore Aursand <>
    "A car is not the only thing that can be recalled by its maker." --
    Unknown
    Tore Aursand, Feb 11, 2004
    #4
  5. In article <>,
    Tore Aursand <> wrote:
    :Better yet, IMO;

    : if ( m,BEGIN\s*(.*?)\s*END,s ) {
    : my $middle = $1;
    : }
    : else {
    : # No match
    : }

    but $middle is going to disappear after that 'if', which is not necessarily
    to be desired.
    --
    Entropy is the logarithm of probability -- Boltzmann
    Walter Roberson, Feb 11, 2004
    #5
    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. Replies:
    0
    Views:
    545
  2. Kevin Spencer

    Re: Simple Simple question!!!

    Kevin Spencer, Jun 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    649
    Kevin Spencer
    Jun 25, 2004
  3. Daniel Frey

    Simple Question - Simple Answer?

    Daniel Frey, Dec 28, 2004, in forum: XML
    Replies:
    4
    Views:
    825
    Daniel Frey
    Jan 12, 2005
  4. Oli

    simple simple question

    Oli, Jan 26, 2004, in forum: ASP General
    Replies:
    10
    Views:
    361
    Roland Hall
    Jan 26, 2004
  5. Peter Bailey

    simple, simple array question

    Peter Bailey, Apr 8, 2008, in forum: Ruby
    Replies:
    7
    Views:
    203
    Peter Bailey
    Apr 8, 2008
Loading...

Share This Page