Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Searching backward

Reply
Thread Tools

Searching backward

 
 
Evan
Guest
Posts: n/a
 
      11-21-2004
Hi guys,

This is a scaled down version of my work

I have a long string

$PASSENGERS ="Tom Departure Newark Arrives Sanfrasico FLIGHT_STATUS2
MORNING FLIGHT DEPARTS FROM DANE REACHES NEWARK AFTERNOON LEAVES
NEWARK AND REACHES SAN FRANSISCO NEXT MORNING"

I have multiple patterns to search within each string defined in a
separate file.

Departure|Arrival
MORNING|AFTERNOON

Need to search for the occurence and position of pattern 1, if found,
search for the occurence and position of pattern 2 and so on. The
search for reasons needs to be done in a backward direction.

Looked at rindex. It searches the string right to left but the problem
using it is that the string cannot be a regexp.

So the only option remains is to use a regexp.

Could anyone suggest any ideas in the direction of approaching this
problem.

- Evan
 
Reply With Quote
 
 
 
 
James Tolley
Guest
Posts: n/a
 
      11-21-2004
"Evan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi guys,
>
> I have multiple patterns to search within each string defined in a
> separate file.
>
> Departure|Arrival
> MORNING|AFTERNOON
>
> Need to search for the occurence and position of pattern 1, if found,
> search for the occurence and position of pattern 2 and so on. The
> search for reasons needs to be done in a backward direction.
>


Something like this should work, if I understand the issue. It's not tested,
though.

my $string = 'test this';
my @regexes = get_regexes(); # ('One|Two','Three|Four')

while(@regexes) {
my $regex = join '|', map {"($_)"} @regexes; # '(One|Two)|(Three|Four)'
$string =~ /.+($regex)/ or last; # get the regex that matches last in
the string
my $match = $1;
# do something with $match
}

hth


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      11-22-2004
Evan <(E-Mail Removed)> wrote:

> I have multiple patterns to search within each string defined in a
> separate file.
>
> Departure|Arrival
> MORNING|AFTERNOON
>
> Need to search for the occurence and position of pattern 1, if found,
> search for the occurence and position of pattern 2 and so on. The
> search for reasons needs to be done in a backward direction.
>
> Looked at rindex. It searches the string right to left but the problem
> using it is that the string cannot be a regexp.



So far you haven't said anything that *requires* a regex.


> So the only option remains is to use a regexp.

^^^^^^^^^^^^^^^

Then there is something you are not telling us.


> Could anyone suggest any ideas in the direction of approaching this
> problem.



Call rindex() 4 times instead of doing 2 pattern matches with 2 alternatives.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
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
Google search result to be URL-limited when searching site, but notwhen searching Web stumblng.tumblr Javascript 1 02-04-2008 09:01 AM
WPA2 backward compatibility with WPA: TKIP and/or AES? =?Utf-8?B?U2NvdCBCYWxmb3Vy?= Wireless Networking 0 10-05-2005 06:15 PM
Backward compatibility problem JimD Wireless Networking 3 11-28-2004 05:50 AM
Backward North America still...backward! Richard DVD Video 17 08-19-2004 04:55 AM
.netframework backward compatable paul ASP .Net 6 01-13-2004 07:41 PM



Advertisments