index($str, [but with regex here])

Discussion in 'Perl Misc' started by Emanuel Berg, Jun 6, 2013.

  1. Emanuel Berg

    Emanuel Berg Guest

    I have this line:

    my $end = index($end_str, " ");

    What I need, is the same (an integer position), only the first
    word delimiter should be taken from a set of possible chars: not
    only whitespace, but end of line, parenthesis, etc.

    I need to be able to define this char by char: for example, I
    *don't* want the slash to be such a delimiter.

    What do you think?

    --
    Emanuel Berg - programmer (hire me! CV below)
    computer projects: http://user.it.uu.se/~embe8573
    internet activity: http://home.student.uu.se/embe8573
    Emanuel Berg, Jun 6, 2013
    #1
    1. Advertising

  2. Emanuel Berg <> wrote:
    >I have this line:
    >
    >my $end = index($end_str, " ");
    >
    >What I need, is the same (an integer position), only the first
    >word delimiter should be taken from a set of possible chars: not
    >only whitespace, but end of line, parenthesis, etc.
    >
    >I need to be able to define this char by char: for example, I
    >*don't* want the slash to be such a delimiter.


    If nothing else you can always do it in two steps (error handling
    omitted):

    $end_str =~ m/([MyReClass])/;
    $end = index($end_str, $1);

    Replace MyReClass with whatever character set you like.

    jue
    Jürgen Exner, Jun 6, 2013
    #2
    1. Advertising

  3. Emanuel Berg

    Emanuel Berg Guest

    Emanuel Berg, Jun 6, 2013
    #3
  4. Emanuel Berg

    Jim Gibson Guest

    In article <>, Emanuel Berg
    <> wrote:

    > Thanks both. I only tried Ben's solution, as he was first and it
    > worked like a charm. I appreciate the crisp explanations.


    You could also use the String::Index module from CPAN, which gives you
    the equivalent of C's strpbrk function (I have not used it).

    --
    Jim Gibson
    Jim Gibson, Jun 7, 2013
    #4
    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. David
    Replies:
    2
    Views:
    471
    Thomas G. Marshall
    Aug 3, 2003
  2. Trevor

    sizeof(str) or sizeof(str) - 1 ?

    Trevor, Apr 3, 2004, in forum: C Programming
    Replies:
    9
    Views:
    617
    CBFalconer
    Apr 10, 2004
  3. Replies:
    3
    Views:
    735
    Reedick, Andrew
    Jul 1, 2008
  4. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    271
    Tomasz Chmielewski
    Mar 4, 2008
  5. Giacomo Alzetta
    Replies:
    10
    Views:
    230
    Giacomo Alzetta
    Nov 22, 2012
Loading...

Share This Page