[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Regex groups / was: Re: Move leading/trailin
Yves Forkl wrote:
Quite simply (and not so in some other regex dialects) the number in your regex-group is guaranteed to match the content of what is matched or not matched by the opening parenthesis with the same index. Meaning: just count all "(" in your regex from the left, and you know what will be in the regex-group(x) where 'x' equals your count. I.e., text is: "this is a text" regex: (t(.+)(.*)) will put the 't' in regex-group(1), the 'his is a text' in regex-group(2) and nothing in regex-group(3) (because of the rules of greedy matching and backtracking, but that is another story). Note that this also includes situations where the branches of the match (by '|' character) would logically break this count. Not so in XSLT, i.e.: regex: (t)|(.) will put all 't' in regex-group(1) and all other chars in regex-group(2). If you want to know whether a regex-group actually matched anything, you can check its string-length. The same rules for regex-group apply to $1, $2 etc, but you can only use them inside replace(), not inside analyze-string. -- Abel Braaksma http://www.nuntia.nl
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|