List Info

Thread: Simple regex to remove an attribute




Simple regex to remove an attribute
country flaguser name
United States
2007-08-09 06:55:12
Hey guys,

I'm really really suck in PHP using preg_replace.

I have some XML, which goes a little like this:

att1="xyz" att2="uio"
att3="qwerty"

where I want to remove the second attribute all together.

Ideally I'd just like to grab everything form
"att2" to "att3" and
replace it with just "att3". I thought that would
be a fairly simple
thing to select, but apparently not.

I've tried this:
[(att2)^(att3)] but it doesn't seem to work at all.

Any help would be really appreciated.

Cheers,
-F


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


Re: Simple regex to remove an attribute
country flaguser name
United States
2007-08-10 05:00:03
Hi F,

Sample text:
att1="xyz" att2="uio"
att3="qwerty"
att1="xyz" att2="bac"
att3="qwerty"
att1="xyz" att1="uio"
att3="qwerty"
att1="xyz" att2="xyz"
att3="qwerty"
att1="xyz" att2="uio"
att3="qwerty"  att3="qwerty"
att1="xyz" att2="cba"
att3="qwerty" att4="qwerty"
att3="qwerty"

Pattern:
(att2=['"][^'"]*['"]s*)att3=

Match $1
att2="uio" att3= att2="uio"
att2="bac" att3= att2="bac"
att2="xyz" att3= att2="xyz"
att2="uio" att3= att2="uio"
att2="cba" att3= att2="cba"

Again, I am assuming att* may be repeated and NOT that ' or
" are
included in your expressions. Ex: att2="O'Donnell"
will return a false
match.

Thanks!
Syd

On Aug 9, 4:55 pm, F <fintan.darr...gmail.com> wrote:
> Hey guys,
>
> I'm really really suck in PHP using preg_replace.
>
> I have some XML, which goes a little like this:
>
> att1="xyz" att2="uio"
att3="qwerty"
>
> where I want to remove the second attribute all
together.
>
> Ideally I'd just like to grab everything form
"att2" to "att3" and
> replace it with just "att3". I thought that
would be a fairly simple
> thing to select, but apparently not.
>
> I've tried this:
> [(att2)^(att3)] but it doesn't seem to work at all.
>
> Any help would be really appreciated.
>
> Cheers,
> -F


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regexgooglegroups.com
To unsubscribe from this group, send email to
regex-unsubscribegooglegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )