xslt 3 regex in replace function

30 views Asked by At

I would like to remove 'a' or 'the' from the beginning of a string, and 'checklist' or 'procedures?' from the end of a string:

input examples:

A Detailed procedure
The flight checklist
Takeoff procedures

Desired output, respectively:

Detailed
flight
Takeoff

Using a variable

<xsl:sequence select="replace($string, '^(a|the)\s(.*)\s(procedures?|checklist)$', '$2', 'i')" />

is returning the complete $string but

<xsl:sequence select="replace('A flight checklist', '^(a|the)\s(.*)\s(procedures?|checklist)$', '$2', 'i')" />

returns flight as expected.

1

There are 1 answers

1
Martin Honnen On BEST ANSWER

I would try replace($string, '(^(a|the))|((procedures?|checklist)$)', '', 'i') or perhaps replace($string, '(^(a|the)\s)|(\s(procedures?|checklist)$)', '', 'i').