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

Re: efficiently extracting a capture group from analy

Subject: Re: efficiently extracting a capture group from analyze-string()
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Jun 2022 16:23:04 -0000
Re:  efficiently extracting a capture group from  analy
On Sat, Jun 04, 2022 at 03:30:03PM -0000, Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx scripsit:
> Hi everyone!
> 
> Given some filename string like
> 
>   <xsl:variable name="file" select="'path/my-sometype.xml'"/>
> 
> Ibd like to extract the bmy-(\w+)b part of the filename using analyze-string().

I would recommend against trying to do this with general application of
a single regular expression.

If you only want something that starts with 'my-' and you're confident
no other path component has 'my-' in it, it'd be:

tokenize($file,'/')[starts-with(.,'my-')]

possibly

tokenize($file,'/')[matches(.,'my-','i')]

if you're not sure it's exactly 'my-'.

Or, classically,

tokenize($file,system-property('file.separator'))[last()]

or if your processor gives you access to the file EXPath module
( http://expath.org/spec/file ) it's modernly

file:name($file)

Standard and library functions always have better test cases; use them
if you can.

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
CC&s oferC)ode, C0isses swC! mC&g.
-- Deor  ("That passed, so may this.")

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.