Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Char, from List, in String 1

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
US
I need to search a string and find the position of the first character found from a list. For example, something like this:

$string = "abcdef";
$pos = index($string,"b|e");

$pos should return "1" in this case because "b" comes before "e" in the string.

Is there a function that does this?

Thanks in advance!
 
The special variable $-[0] holds the position of the start of the last successful match in a regular expression. You can use it like so:
Code:
my $string = 'abcdef';
if ( $string =~ /[be]/ ) {
   print "Position is: $-[0]\n";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top