[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: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 4 Jun 2022 17:22:10 -0000
 Re: efficiently extracting a capture group from  analy
Hi Gerrit, Graydon,

Thanks for having a look!

The tricky part is, I need an empty sequence if the input string does not
comply with pattern. replace() returns the original string for a non-match. I
could address that with a prefilter:

  replace($file[matches(., '/my-(\w+)\.xml$')], '^.+/my-(\w+)\.xml$', '$1')

but I don't like duplicating patterns because they can accidentally become
desynchronized. (If anyone suggests an ENTITY as a solution here, please see
me after class.)

Graydon, I need your solution for obtaining the file basename elsewhere in my
stylesheet -- thank you!! -- but I run into the prefilter double-pattern issue
whether I replace()the full path or just the basename.

And although this example processes a filename, I'd like to find best
generalized way to obtain a capture group (or nothing) for any match scenario.
In perl, I can assign a variable to the result of a regex match:

  my $file = 'path/my-sometype.xml';
  my ($type) = ($file =~ m{my-(\w+)});

and I was hoping for something similar in XQuery.

Thank you everyone! It's nice to be able to group-think through this.

- Chris


XSL-List info and
archive<https://urldefense.com/v3/__http:/www.mulberrytech.com/xsl/xsl-list__
;!!A4F2R9G_pg!YXd556WaLkP4pGQ6edPoLq22GVZWXz0FWKC8B6fG3pWIEv49hMn2JEHevovei-D
Y16w5mb_F-bFG4sPyBrcYYJwk3mBc3dJ69yblgscpjoSpFqlrlsgk$>
EasyUnsubscribe<https://urldefense.com/v3/__http:/lists.mulberrytech.com/unsu
b/xsl-list/3380743__;!!A4F2R9G_pg!YXd556WaLkP4pGQ6edPoLq22GVZWXz0FWKC8B6fG3pW
IEv49hMn2JEHevovei-DY16w5mb_F-bFG4sPyBrcYYJwk3mBc3dJ69yblgscpjoSpFguJxHbP$>
(by email<>)

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.