TonyP
TonyP

Reputation: 5873

RegEx to match starting element containing specific sequence of characters

I have this XML document fragment..

<fsm> <fparameters> <fparameter name="fsOAPath"><%#sqlscalar:select dbo.fsOaPath(<%OrderId%>)%></fparameter> </fparameters> <do> <action> <context source="/notification/fsm/parameters/parameter[@name='fsOAPath']" destination="/notification/message/parameter[@name='Body']" /> </action> </do> </fsm> <message> <parameter name="AlternateViews">text/html</parameter> <parameter name="Attachements" /> <parameter name="Body" /> <parameter name="Sender">Expresslane <%# sqlscalar:select @@servername%> </parameter> <parameter name="Subject" /> <parameter name="SubjectEncoding"/> <parameter name="To"><%#sqlscalar:select dbo.fsEmailReceipientOfOrder(<%OrderId%>)%> </parameter> </message> </fsm>

And this Regex

(?<vars>(?><%[\s]*)\w+(?>[\s]*%>))

which maches <%OrderId%> text in the nodes /fsm/fparameters/fparameter[@name='fsOAPath"] and /fsm/message/parameter/[@name='To'] What is the regex for including the local node's local name of fparameter and parameter

Upvotes: 0

Views: 90

Answers (1)

Stephan
Stephan

Reputation: 43023

Try this regex:

<(?<localName>[^\s]+).+(?<vars>(?><%[\s]*)\w+(?>[\s]*%>))

Demo

http://regex101.com/r/zI7zW8

Upvotes: 1

Related Questions