Project

Profile

Help

fn:matches regex

Added by Anonymous over 15 years ago

Legacy ID: #7533487 Legacy Poster: Tobias Klevenz (tklevenz)

Hi, there. Just to follow up on a comment I posted on Twitter the other day. Here's what the Problem was: I had an XML like: <a> <b Code="it1">value</b> <b Code="it2">value</b> <b Code="it3">value</b> ... <b Code="it1_1">value1</b> <b Code="it2_1">value1</b> <b Code="it3_1">value1</b> ... </a> I had to put them in a table so that it1_1 belongs to it1 so I did: <xsl:for-each select="b[matches(@Code,'it[0_9][^_]')]"> trying to only select the it* but not it*_1 (using Oxygen if I search for it[0_9][^_] with regex enabled this works fine) Running the Transformation with saxon however, this didn't select anything. I quickly worked around it with a combination of contains and substring-after. Question though, shouldn't that regex work in the transformation? Regards, Tobias


Replies (3)

Please register to reply

RE: fn:matches regex - Added by Anonymous over 15 years ago

Legacy ID: #7533514 Legacy Poster: Michael Kay (mhkay)

Did you mean it[0-9][^_] perhaps? My understanding is that this matches "it" followed by a digit followed by a character that is not an underscore. It won't match "it5" because the digit is not followed by a character that matches [^_]. Perhaps you should use "^it[0-9]$"

RE: fn:matches regex - Added by Anonymous over 15 years ago

Legacy ID: #7533570 Legacy Poster: Tobias Klevenz (tklevenz)

"followed by a character that is not an underscore" True, I didn't think of it that way, I guess the way Oxygen handles that "no charachter" or maybe \b which marks the end of the Word as I understand is included in that too. I guess it depends on the implementation of regex then. Regex is still kind of a mystery to me, that is really fun playing with though. Thanks, Tobias

RE: fn:matches regex - Added by Anonymous over 15 years ago

Legacy ID: #7533583 Legacy Poster: Michael Kay (mhkay)

Oxygen is probably searching the raw XML text, in which case the [^_] matches the closing quote of the attribute value. There's no \b in XPath regular expressions because of internationalization issues.

    (1-3/3)

    Please register to reply