Opened 11 years ago
Closed 10 years ago
#6493 closed Bugs (invalid)
Problem in using regex to find nested tags
Reported by: | Owned by: | John Maddock | |
---|---|---|---|
Milestone: | To Be Determined | Component: | regex |
Version: | Boost 1.48.0 | Severity: | Problem |
Keywords: | regex | Cc: |
Description
I want to use regex to find all "<NPC></NPC>"
like tags in a text file, and tags may recursive. So I made an example, using patterns
<(?<HtmlTag>NPC)>((?<Nested><\k<HtmlTag>>)|</\k<HtmlTag>>(?<-Nested>)|.*?)*</\k<HtmlTag>>
to search string
abc<NPC><NPC>12345</NPC>1</NPC>2<NPC>3</NPC>
Well, it works well in Expresso(a cool tool in making and testing regular expressions, can be found at http://www.ultrapico.com/
). But by using boost::regex_search, it returns the whole string. It seems that the 3rd "<NPC>"
matches ".*?"
but "</\k<HtmlTag>>"
.
Attachments (1)
Change History (2)
by , 11 years ago
comment:1 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Perl and .Net regular expression are similar but not the same - Perl matches the whole of the input string as well.
Suggest you try a recursive expression: http://www.boost.org/doc/libs/1_50_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html#boost_regex.syntax.perl_syntax.recursive_expressions
An example in using regex