How can I strip keywords out of a search string

B

blnukem

How can I strip keywords "machinery liquidator" out of a search string I
cant seem to loose the "web/" in my query results

my $String =
'http://msxml.excite.com/info.xcite/search/web/machinery+liquidator';

#my($Domain,$Query) = $ String =~m((http://.+?)/.*?(web/)([^&]*));
#my($Domain,$Query) = $ String =~m((http://.+?)/.*(web/)([^&]*));
#my($Domain,$Query) = $ String =~m((http://.+?)/.*[web/]([^&]*));

my($Domain,$Query) = $ String =~m((http://.+?)/.*?(web/[^&]*));

print "Domain: $Domain";
print"<br>Query: $Query";
 
S

Sherm Pendley

blnukem said:
How can I strip keywords "machinery liquidator" out of a search string I
cant seem to loose the "web/" in my query results
^^^^^
"loose" ne "lose" (It's a pet peeve...)
my $String =
'http://msxml.excite.com/info.xcite/search/web/machinery+liquidator';

my($Domain,$Query) = $ String =~m((http://.+?)/.*?(web/[^&]*));

print "Domain: $Domain";
print"<br>Query: $Query";

If you don't want it, don't capture it. Just move it outside of the
second subexpression:

#!/usr/bin/perl

use warnings;
use strict;

my $String =
'http://msxml.excite.com/info.xcite/search/web/machinery+liquidator';

my($Domain,$Query) = $ String =~m((http://.+?)/.*?web/([^&]*));

print "Domain: $Domain\n";
print" Query: $Query\n";

sherm--
 
M

Michele Dondi

How can I strip keywords "machinery liquidator" out of a search string I
cant seem to loose the "web/" in my query results

my $String =
'http://msxml.excite.com/info.xcite/search/web/machinery+liquidator';

#my($Domain,$Query) = $ String =~m((http://.+?)/.*?(web/)([^&]*));
#my($Domain,$Query) = $ String =~m((http://.+?)/.*(web/)([^&]*));
#my($Domain,$Query) = $ String =~m((http://.+?)/.*[web/]([^&]*));

You can assign to undef. You can take a slice. You can use
non-capturing parentheses. Please also note that

$ String

doesn't add to readability. Or is it supposed to be a JAPH?!?


Michele
 
S

Sherm Pendley

Andrew said:
blnukem wrote on 11 Декабрь 2004 12:15:



URI.pm will help you

Did you *try* URI.pm with the string shown? Note that the query is
passed as extra path info, *not* separated by a "?" - URI.pm's path()
method returns everything after the host name, and its query() method
returns undef.

sherm--
 
A

Andrew Tkachenko

blnukem wrote on 11 Декабрь 2004 12:15:
How can I strip keywords "machinery liquidator" out of a search string I
cant seem to loose the "web/" in my query results

my $String =
'http://msxml.excite.com/info.xcite/search/web/machinery+liquidator';

#my($Domain,$Query) = $ String =~m((http://.+?)/.*?(web/)([^&]*));
#my($Domain,$Query) = $ String =~m((http://.+?)/.*(web/)([^&]*));
#my($Domain,$Query) = $ String =~m((http://.+?)/.*[web/]([^&]*));

my($Domain,$Query) = $ String =~m((http://.+?)/.*?(web/[^&]*));

print "Domain: $Domain";
print"<br>Query: $Query";


URI.pm will help you
 
S

Sherm Pendley

Andrew said:
my $uri = new
URI("http://msxml.excite.com/info.xcite/search/web/machinery+liquidator");
print "Domain:", $uri->authority, "\n", "Query:", ($uri->path_segments)[-1],
"\n";

Why not ? I'm too lazy to care about parsing URIs by hand.

Two reasons:

First, the above approach only works if the query string has no '/'s.

And second, blnukem didn't ask about parsing URIs - he asked why his
regex wasn't matching what he thought it should. Neither you nor I knows
for sure whether he's actually processing URIs for real, or simply using
them as an exercise for learning regexes.

sherm--
 
A

Andrew Tkachenko

Sherm Pendley wrote on 11 Декабрь 2004 21:39:
Did you *try* URI.pm with the string shown? Note that the query is
passed as extra path info, *not* separated by a "?" - URI.pm's path()
method returns everything after the host name, and its query() method
returns undef.

sherm--

my $uri = new
URI("http://msxml.excite.com/info.xcite/search/web/machinery+liquidator");
print "Domain:", $uri->authority, "\n", "Query:", ($uri->path_segments)[-1],
"\n";

Why not ? I'm too lazy to care about parsing URIs by hand.
If I do something wrong, I'd appreciate you comments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top