-1

I have this regex

<SharePointWebControls:(\w+|_)+[=" _\w]*?(fieldname="(\w+|_)+")?[="' _\w<>%$:,]*?\/> with mode gi

and I'm testing it against

<SharePointWebControls:FieldValue id="PageStylesField" FieldName="HeaderStyleDefinitions" runat="server" />

And I want to capture two strings, FieldValue and HeaderStyleDefinitions. However the fieldname attribute may not exist, in which case just capture the first string, but if it exists, then capture both.

But in my regex, it always only captures the first string. Does anyone know how to fix it?

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
omega
  • 40,311
  • 81
  • 251
  • 474
  • -1 Please stop trying to invoke the wrath of Cthulu http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Aron Aug 14 '15 at 06:52

1 Answers1

0

You should not be using regex for XML comprehension. Use an XML parser instead.

Aron
  • 15,464
  • 3
  • 31
  • 64