Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > index($str, [but with regex here])

Reply
Thread Tools

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

 
 
Emanuel Berg
Guest
Posts: n/a
 
      06-06-2013
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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      06-06-2013
Emanuel Berg <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Emanuel Berg
Guest
Posts: n/a
 
      06-06-2013
Thanks both. I only tried Ben's solution, as he was first and it
worked like a charm. I appreciate the crisp explanations.
--
Emanuel Berg - programmer (hire me! CV below)
computer projects: http://user.it.uu.se/~embe8573
internet activity: http://home.student.uu.se/embe8573
 
Reply With Quote
 
Jim Gibson
Guest
Posts: n/a
 
      06-07-2013
In article <(E-Mail Removed)>, Emanuel Berg
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with printing a bit pattern with printf and %x matt.jaffe@gmail.com C Programming 9 04-19-2013 12:14 PM
Inconsistent behaviour os str.find/str.index when providing optional parameters Giacomo Alzetta Python 10 11-22-2012 06:22 PM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
what's the deference between str=null and str=" " ???????? David Java 2 08-03-2003 04:10 PM



Advertisments