tested in .NET - works fine
balancing goup regex:
( \w+{) # Find the first curly bracket, preceded
by resourceType
coded as \w+
( # one of these three things:
{(?<DEPTH>) # another opening curly bracket
(and increment
DEPTH)
| # or
}(?<-DEPTH>) # closing curly bracket (and
decrement DEPTH)
| # or
.*? # anything else (lazily)
)* # and repeat.
(?(DEPTH)(?!)) # Match if depth == 0, i.e., the
initial if is
balanced.
(}) # Conclude with the final curly bracket
#END REGEX
from input:
resourceType{
field1 = aValue,
field2 = "value with quotation marks",
field3 = "value with quotation mark and in
the field value",
field4 = ,
lastfield = "should not have a delimiting comma, but
some generators do
anyhow"
}
{some other HTML code}
resourceType{
field1 = aValue,
field2 = "value with quotation marks",
field3 = "value with quotation mark and
in the field
value",
field4 = ,
lastfield = "should not have a delimiting comma, but
some generators do
anyhow"
}
}
{some other HTML code}
it matches both resource type as 2 matches. Try it in
Expresso.
code for C# regex object : Watch OPTIONS !!
using System.Text.RegularExpressions;
Regex regex = new Regex(
"( \w+{) # Find the first curly bracket
( "
+ " # one of these three things:
{(?<DEPTH>) "
+ " # another opening curly bracket (and
increment DEPTH)
"
+ "| # or
}(?<-DEPTH>) # closing "
+ "curly bracket (and decrement DEPTH)
| "
+ " # or
.*? # anything else (lazily)
"
+ ")* # and repeat.
(?(DEPTH)(?!)) "
+ "# Match if depth == 0, i.e., the initial if is
balanced.
(}"
+ ") # Conclude with the final
curly bracket",
RegexOptions.IgnoreCase
| RegexOptions.Singleline
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Regex" group.
To post to this group, send email to regex googlegroups.com
To unsubscribe from this group, send email to
regex-unsubscribe googlegroups.com
For more options, visit this group at http://groups.go
ogle.com/group/regex
-~----------~----~----~----~------~----~------~--~---
|