|
Subject: RE: [xsl] regular expression in replace() From: UlyLee <ulyleeka@xxxxxxxxx> Date: Tue, 18 Oct 2005 05:06:49 -0700 (PDT) |
oooppss... i think this is a much shorter solution :D
o well at least i tried :D
thanks again guys!
--- Michael Kay <mike@xxxxxxxxxxxx> wrote:
> Schema Part 2 says:
>
> A metacharacter is either ., \, ?, *, +, {, } (, ),
> [ or ]. These characters
> have special meanings in .regular expression.s, but
> can be escaped to form
> .atom.s that denote the sets of strings containing
> only themselves, i.e., an
> escaped .metacharacter. behaves like a .normal
> character..
>
> and XPath adds ^ and $ to the list.
>
> So you can turn your replacement string into a regex
> using
>
> replace($in, "[.\\?*+{}()\[\]^$]", "\\$0")
>
> Note that in both the regex and the replacement
> string, \ is represented as
> \\.
>
> Not tested.
>
> Michael Kay
> http://www.saxonica.com/
>
>
> > -----Original Message-----
> > From: UlyLee [mailto:ulyleeka@xxxxxxxxx]
> > Sent: 18 October 2005 12:52
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: [xsl] regular expression in replace()
> >
> > I have a string: "Lucie et Suz. Beauvais Suzanne"
> and
> > i want to replace "Suz." with "Suzanne".
> >
> > but when i use replace("Lucie et Suz. Beauvais
> > Suzanne","Suz.","Suzanne") it gives me "Lucie et
> > Suzanne Beauvais Suzannenne", i figured that this
> is
> > because "." is treated as a regular expression
> thats
> > why it replaced "Suza" with "Suzanne". I know i
> need
> > to escape the "." to "\." but what if my
> > replace-pattern contains other regex characters
> like
> > "?" "*" "+"?
> >
> > Michael Kay suggested that i first make my
> replacement
> > string to regelar expression or create a replace
> > function that uses substring-before() and
> contains().
> > How am i to go around this? I'm just starting out
> in
> > XSL and the new features of XSLT 2.0 sometime
> confuses
> > me.
> >
> > My first alternative was to use
> replace($sourceStr,
> > ".", "\.") but it says "\." is an invalid
> replacement string.
> >
> >
> >
> > __________________________________
> > Yahoo! Music Unlimited
> > Access over 1 million songs. Try it free.
> > http://music.yahoo.com/unlimited/
>
>
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] regular expression in rep, David Carlisle | Thread | [xsl] RE : [xsl] xsl:sort blocks of, Stephane Dion |
| Re: [xsl] regular expression in rep, David Carlisle | Date | [xsl] RE : [xsl] xsl:sort blocks of, Stephane Dion |
| Month |