I'm trying to build a regular expression to work with the .NET Regex object. The expression is designed to parse a forum tag such as [foo bar="foo"] - it should also recognise attributeless tags [foo] and self closing tags [foo /] or [foo bar="foo" /]
Here is what I have so far:
For some reason this fails to capture the group represented by (\w+) - the pattern matches but completly fails to capture that group. It's weird.
If I take out the conditional - that's the bit that starts (?(?= - then it matches the pattern correctly for tags which have attributes (see below)
If the damn thing would capture groups it's supposed to I wouldn't be having this problem
Any ideas?
Yet another unchecked rambling brought to you by:
Oddball
Here is what I have so far:
Code:
\[((?=[^/]).*?)(?(?=\s\w+=".+?")(?:\s(\w+)="(.+?)")*(?:\s(/))?\]|(?:\s(/))?\])
For some reason this fails to capture the group represented by (\w+) - the pattern matches but completly fails to capture that group. It's weird.
If I take out the conditional - that's the bit that starts (?(?= - then it matches the pattern correctly for tags which have attributes (see below)
Code:
\[((?=[^/]).*?)(?=\s\w+=".+?")(?:\s(\w+)="(.+?)")*(?:\s(/))?\]
If the damn thing would capture groups it's supposed to I wouldn't be having this problem
Any ideas?
Yet another unchecked rambling brought to you by:
Oddball