Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Match url beginning with http:// or nothing.

Reply
Thread Tools

Match url beginning with http:// or nothing.

 
 
Heckner
Guest
Posts: n/a
 
      07-11-2005
Hi

I tried /(http:\/\/w+|^)/ as the regex for matching an url beginning
with http:// or an empty string.
Problem is the empty string is not matched. Any idea?
Best regards
Hannes

 
Reply With Quote
 
 
 
 
echohtp@gmail.com
Guest
Posts: n/a
 
      07-11-2005
well im not sure what it is but that "empty string" character is either
wrong or just displaying wrong here, this is what you would want

/(http:\/\/\w+|\s+)/ you missed the \ for the w+ and the s+ hopefully
this will fix your problem

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      07-11-2005
Heckner wrote:
> I tried /(http:\/\/w+|^)/ as the regex for matching an url beginning
> with http:// or an empty string.
> Problem is the empty string is not matched. Any idea?


It matches a section sign as expected. You mean

/(http:\/\/w+|^$)/
-------------------^

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      07-11-2005
Gunnar Hjalmarsson <(E-Mail Removed)> writes:

> Heckner wrote:
>> I tried /(http:\/\/w+|^)/ as the regex for matching an url beginning
>> with http:// or an empty string.
>> Problem is the empty string is not matched. Any idea?

>
> It matches a section sign as expected. You mean
>
> /(http:\/\/w+|^$)/
> -------------------^


In addition, you could avoid "leaning toothpick syndrome" by using a different
delimiter for the match:

m%(http://w+|^$)%

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
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
index of string from beginning of line vs beginning of file Jesse B. Ruby 9 03-27-2010 04:04 PM
match matching chars at beginning of STL string Lars Schouw C++ 1 03-26-2010 12:10 AM
$match = true() for empty $match?? Victor XML 2 05-17-2004 10:43 AM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM
Match beginning of two strings Ravi Python 20 08-22-2003 07:28 AM



Advertisments