Regex: Tüm uygunsuz etiket niteliklerini eşleştirme

0 Cevap php

Bir örnek girişi için:

<a href="abc" something=b foo="bar" baz=cool>

Ben maç için çalışıyorum:

something=b
baz=cool

Preg_match_all kullanırken bile Ancak, I sonuna kadar her şeyi sadece ilkini (bir şey = b) maç olacak. Ben kullanıyorum düzenli ifadedir:

<\w+.*?(\w+=[^"|^'|^>]).*?>

Veya:

<\w+ # Word starting with <
.*?  # Anything that comes in front of the matching attribute.
(
\w+  # The attribute
=
[^"|^'|^>]+? # Keep going until we find a ", ' or >
)
.*? # Anything that comes after the matching attribute.
> # Closing >

Herhalde normal ifadeler için oldukça yeni korkunç yanlış bir şey, yapıyorum. Lütfen tavsiye! :)

edit:

Revize düzenli ifade:

<\w+.*?\w+=([^"\'\s>]+).*?>

Ben orada çok zzz = aaa maç istiyorum ;)

0 Cevap