Project

Profile

Help

puzzling regex problem

Added by Anonymous over 18 years ago

Legacy ID: #3352138 Legacy Poster: xristy (xristy)

I'm using saxonB 8.5.1. I have data like: <outline:name>Volume KA - 1</outline:name> and: <outline:name>Volume PHA - 14</outline:name> I am using: <xsl:analyze-string select="." regex="vol.\s([0-9][0-9])" flags="i"> <xsl:matching-substring> <outline:vol> <xsl:value-of select="regex-group(1)"/> </outline:vol> </xsl:matching-substring> </xsl:analyze-string> The problem that I have is that no matter what contortions I go to with the regex, regex-group(1) is always the only or last digit - that is I get "1" for "1" and "0" for "10" and "1" for "11". I've tried regex="vol.\s*([0-9]+)" and regex="vol.\s([0-9]{{2}}|[0-9]{{1}})" The last in a fit of desparation -;) As I understand the specs the first choice dominates if it matches, but in all cases the result element is just a single digit: <outline:vol>1</outline:vol> If I use an expression like: regex="vol.\s([0-9]{{2}})" I indeed get just the two digit cases: <outline:vol>22</outline:vol> and so on. I'm beyond puzzled about how to use the XSL regex feature. Thanks in advance for any help with this problem


Replies (2)

RE: puzzling regex problem - Added by Anonymous over 18 years ago

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

With this regex: vol.\s([0-9][0-9]) and this input Volume PHA - 14 the matching is as follows: "vol" matches "Vol" . matches "ume PHA - 1" \s* matches nothing [0-9][0-9]* matches "4" Perhaps you meant \s+, requiring at least one space before the final number. Michael Kay http://www.saxonica.com/

RE: puzzling regex problem - Added by Anonymous over 18 years ago

Legacy ID: #3352214 Legacy Poster: xristy (xristy)

Thanks. As it turns out, for my purposes: regex="vol.?([0-9][0-9])" may be more robust since there might not be a \s before the number.

    (1-2/2)

    Please register to reply