xsl-list
[Top] [All Lists]

Re: [xsl] xslt 2.0 regex and how to test it

2006-03-19 08:43:50
Manfred Staudinger wrote:

    <xsl:value-of select="replace(., '\[[^\]]+\]', '')"/>

Thanks for your solution, works perfect.
Let me try to verbalize the regex (" for better readability):
"\[[^\]]+\]"
the string starts with "[" and ends with "]": SingleCharEsc
"\[" and "\]"
in between there is a charGroup: "[]"
with a quantifier "+" for one or more occurrences
the charGroup is a negcharGroup, as it starts with: "^"
it contains one character "]": SingleCharEsc "\]",
thus allowing for one or more characters which are not "]".

  Perfectly right (I mean, it's what I'd have said).

I would prefer to try it out with an editor's find. To my
surprise your solution worked fine with SciTE.

  Ok.  Regexps are supported in a lot of languages and tools.  But with
some differences and/or enhancements.  Emacs for example have a tool
that helps to build regexps: re-builder.  Maybe your editor have such a
functionality.  If you are aware of these differences, it can be a good
way to design a complex regexp.  But it's not the way to learn a
specific regexps language in particular, IMHO (here XPath 2.0 regexps).

  If you don't want to write each time an XSLT script and a input
document to test one regexp, you can write an extension to your
favorite editor.  In Emacs, this could be done quite easily, I think. 
Or a specific client for your XSLT processor (for example a Java client
for Saxon, taking a regexp and a text to test matching, and building a
simple script from these).

One difference I noted was, that SciTE does not need
the SingleCharEsc within the charGroup.

  It's the way traditional regexps work.  I must confess it's what I
tried first.  But Saxon gave me the right advice to escape it.  A good
thing IMHO, more rigorous.

  Regards,

--drkm



        

        
                
___________________________________________________________________________ 
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs 
exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>