[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Regex groups / was: Re: Move leading/trailing s

Subject: Regex groups / was: Re: Move leading/trailing spaces outside (XSLT 2.0)
From: Yves Forkl <Y.Forkl@xxxxxx>
Date: Tue, 06 Feb 2007 17:44:21 +0100
 Regex groups / was: Re:  Move leading/trailing  s
Abel Braaksma wrote:

Please note the subtle differences between the above mentioned
solution and the one I proposed. Both have their pros and cons.
Depending on your final needs, one or the other may suit you best.
Using [as the above mentioned solution suggested]

<xsl:analyze-string select="." regex="^(\s*)(.+?)(\s*)$">

will match the total string, so no need for using non-matching-substring. This has the advantage that you can do string-manipulation on the whole match at once, using regex-group(1), (2) and (3). If you only do string-replacement, your can optimize this with the replace() function.

Though familiar with RegExp functions in various languages, I am not sure how this one works, so I wonder what happens when the condition of the first regex group cannot be satisfied. Supposing that the second matches, will I then have to refer to it as regex-group(1) or still as regex-group(2)? I.e., do the numbers index the groups defined in the regex or the substrings that actually matched one of the groups?



Doing

<xsl:analyze-string select="." regex="^\s+|\s+$">

is quicker, has the advantage of separating logic, but has the disadvantage that you cannot intermix the matching and non-matching strings (meaning, when you are in non-matching-substring, it contains the non-space content of your match, and you cannot get the matching-substring from that instruction and vice versa).

The latter technique seems to perfectly solve my task of simply "squeezing" leading and trailing spaces from element content out into mixed content.


Thank you again for your efforts in providing me all this information.

Yves

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.