in reply to out of two strings which occurs first in a text
If it matches any string, the special variable '$1' will hold the first match.#!/usr/bin/perl -w use strict; my $str = "is the best way to match which of two strings occurs first +in a text"; my $first = "two"; my $second = "match"; $str =~ m/($first|$second)/g; print $1 if($1); # $1 will hold first matched value
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: out of two strings which occurs first in a text
by ikegami (Patriarch) on Sep 24, 2008 at 09:32 UTC | |
by jwkrahn (Abbot) on Sep 24, 2008 at 10:05 UTC | |
by wol (Hermit) on Sep 24, 2008 at 13:35 UTC | |
by dec (Beadle) on Sep 24, 2008 at 13:39 UTC | |
by ikegami (Patriarch) on Sep 24, 2008 at 20:28 UTC | |
|
Re^2: out of two strings which occurs first in a text
by CountZero (Bishop) on Sep 24, 2008 at 09:21 UTC |