Regular Expressions
Hi Guys,
I am currently working on the following to completely replace the <a
href> tag and all content but its not working:
$input = "<a href=\"some_random_text.html?tes=hello&str=pol%20\">Text
here</a>";
echo ereg_replace('<a href="[A-Za-z0-9._-][&\?=]+">',"", $input);
Will keep working on it but if you get there first any help would be
great.
Thanks
A
Re: Regular Expressions
On Jan 29, 11:39 am, UKuser <spiderc... [at] yahoo.co.uk> wrote:
> Hi Guys,
>
> I am currently working on the following to completely replace the <a
> href> tag and all content but its not working:
>
> $input = "<a href=\"some_random_text.html?tes=hello&str=pol%20\">Text
> here</a>";
> echo ereg_replace('<a href="[A-Za-z0-9._-][&\?=]+">',"", $input);
>
> Will keep working on it but if you get there first any help would be
> great.
>
> Thanks
>
> A
Done it - solution is <a href="[^"]+">
Re: Regular Expressions
UKuser wrote:
> Hi Guys,
>
> I am currently working on the following to completely replace the <a
> href> tag and all content but its not working:
>
> $input = "<a href=\"some_random_text.html?tes=hello&str=pol%20\">Text
> here</a>";
> echo ereg_replace('<a href="[A-Za-z0-9._-][&\?=]+">',"", $input);
At first glance:
[A-Za-z0-9._-] is a characterclass, but you forgot the + after it, so it
matches 1 or more times.
Secondly: [&\?=]+ will not match
test.html?name=joe&age=11
Wouldn't it be easier to simply try to match:
1) begins with: <a href="
2) then anything
3) ends with: >
in a nongreedy way?
Regards,
Erwin Moller
>
> Will keep working on it but if you get there first any help would be
> great.
>
> Thanks
>
> A
Re: Regular Expressions
UKuser wrote:
> On Jan 29, 11:39 am, UKuser <spiderc... [at] yahoo.co.uk> wrote:
>> Hi Guys,
>>
>> I am currently working on the following to completely replace the <a
>> href> tag and all content but its not working:
>>
>> $input = "<a href=\"some_random_text.html?tes=hello&str=pol%20\">Text
>> here</a>";
>> echo ereg_replace('<a href="[A-Za-z0-9._-][&\?=]+">',"", $input);
>>
>> Will keep working on it but if you get there first any help would be
>> great.
>>
>> Thanks
>>
>> A
>
> Done it - solution is <a href="[^"]+">
Hi,
That misses:
< a href=
or
<a href =
I am not sure if that is a problem.
Regards,
Erwin Moller
Re: Regular Expressions
Erwin Moller wrote:
> UKuser wrote:
>> On Jan 29, 11:39 am, UKuser <spiderc... [at] yahoo.co.uk> wrote:
>>> Hi Guys,
>>>
>>> I am currently working on the following to completely replace the <a
>>> href> tag and all content but its not working:
>>>
>>> $input = "<a href=\"some_random_text.html?tes=hello&str=pol%20\">Text
>>> here</a>";
>>> echo ereg_replace('<a href="[A-Za-z0-9._-][&\?=]+">',"", $input);
>>>
>>> Will keep working on it but if you get there first any help would be
>>> great.
>>>
>>> Thanks
>>>
>>> A
>>
>> Done it - solution is <a href="[^"]+">
>
> Hi,
>
> That misses:
> < a href=
> or
> <a href =
>
> I am not sure if that is a problem.
>
> Regards,
> Erwin Moller
Yeah, it was about that sort of time when I first encountered regexps,
that I gave up and decided that I would settle down and write a state
machine in 'C' and consider every possible combination of words/letters,
and write a custom routine.
Never touched em since. Spawn of the devil.