Re: Re: Help with Regular Expressions
| From: | Octavian Rasnita | Date: | Sun, 15 Aug 2004 15:36:42 +0000 |
| Subject: | Re: Re: Help with Regular Expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193887@lists.php.net to get a copy of this message | ||
From: <killu0007-widget@yahoo.co.in>
> Hi all,
>
> I am working on a small php script which should do the
> following. I want all the links in the page to be
> preceded by first character and first two characters
> of the link.Please look into the example below for
> more
> clarification.
>
> eg.
> <a href="/code.html">link here</a> to be
> replaced as
> <a href="/c/co/code.html">link here</a>
>
> I guess, this is possible by using regular expressions
> but I am not able to crack the right expression.
>
Hi,
This is not very simple.
The URI which in your example is /code.html can be anything, including
something like m.html.
In that case which would be the first 2 letters?
Or, the URI can be something like m-like.html. In this case the first 2
letters will be "m-" or "ml"?
A good regular expression should work in all situations so it is important
to know what is the desired result, and not to asume that there won't be any
links like "/.html" or something worse.
Teddy