0

I write a Regex to get the attrs in a tag. But it got a problem when the attrs only has one letter

(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[']?[>"]))+.)["']?

When it to analysis this:

href='www.google.com' target="_blank" title="S"

it will get:

[[href, www.google.com],[target, _blank],[title, "S]]

How can I get:

[[href, www.google.com],[target, _blank],[title, S]]
Vishwas
  • 343
  • 2
  • 13

1 Answers1

1

This expression might return the desired outcomes:

([^=]+)=["']([^'"]*)["']

DEMO 1

Edit:

Other options would be:

(\S+)="(.*?)"|(\S+)='(.*?)'

DEMO 2

(\S+)="([^"\r\n]+)"|(\S+)='([^'\r\n]+)'

DEMO 3

Emma
  • 27,428
  • 11
  • 44
  • 69