Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex parsing of ASP.NET tags
    primarykey
    data
    text
    <p>I have a program to parse various file formats with a goal to find localizable strings (GetText pretty much). I'm looking for a regex that would get "TEXT TO TRANSLATE" from within specific opening and closing tag. I had a working regex but the following example broke it, thanks to the IsVisible call.</p> <pre><code>&lt;mw:Translate runat="server" Visible='&lt;%# IsVisible() %&gt;'&gt; TEXT TO TRANSLATE &lt;/mw:Translate&gt; </code></pre> <p>This is what I have so far but got stuck with it...any help? I have described my wrongly regexxed intentions in //comments...</p> <pre><code>(?s) //multiline flag \&lt;mw\:Translate //opening &lt;mw:Translate&gt; tag (?:(?![^"']+\s*\&gt;)+) //match anything but &gt; preceeded by " or ' //with any whitespace after it (?:["']+\s*)\&gt; //match &gt; preceeded by " or ' with any //whitespace after it \s* //match any whitespace //(for trimming any whitespace around the text) (?&lt;text&gt;.*?) //capturing group for the localizable text \s* //match any whitespace \&lt;/mw\:Translate\&gt; //match closing tag </code></pre> <p>The problem I have is probably in the opening tag...I'm trying to match the closing bracket > only when it is preceeded by " or ' with no or any whitespace after that...because otherwise it's either something like %> or it's not a valid ASP.NET</p> <p>EDIT 1: <strong>Please read the question before coming to conclusions. This is not HTML but ASP.NET which cannot be possibly parsed well with any HTML parsers. I'm also targeting something very specific.</strong> Correction: people seem to agree it can be parsed with HtmlAgility pack but I don't really want to use it, because I don't really like to rely on an external lib for one simple use case.</p> <p>EDIT 2: mw:Translate cannot be nested. It simply won't compile because of how the mw:Translate is programmed.</p> <p>EDIT 3: Clarification of edits.</p> <p>EDIT 4: Self closing mw:translate is not permitted</p> <p>EDIT 5: HTML inside mw:Translate is as valid as any other text on ASP.NET page</p> <p>EDIT 6: answered myself, the regex I'd need may be a bit more complicated (but not because of any relation with HTML), see below</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload