Jump to content

Concatenated Regex with a Variable


iwato

Recommended Posts

The PROBLEM: Consider the following concatenated string and $tag variable'(.+</'.$tag.'(>|\s[^>]*>)|)'The $tag variable is a string containing the name of an HTML tag. The concatenated string is later combined with other strings (not shown) to form a regex pattern for use with a PCRE function.INTERPRETATION: In order to understand the concatenated string above I replace the value of the $tag variable with 'tag' and remove the internal single quote delimiters, as well as the concatenation operators. In so doing I obtain the following three alternative patterns:

  1. '.+</tag>'
  2. '.+</tag(\s[^>]*>)'
  3. '()'

Although I can easily make sense of the first and third patterns, I am having trouble making sense of the second pattern. I have never seen an HTML closing tag with white space and other characters between the </tag characters and the > character.Have I misinterpreted the string '(.+</'.$tag.'(>|\s[^>]*>)|)' ?If not, can you give an example of what the subpattern (\s[^>]*>) might be anticipating?Roddy

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...