Wrox Programmer Forums
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2008, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default regex

Hi,
I have a text as shown below. I need regular expression to match the conditions and replace. The number at two positions should be same(1 or 2 or any). The letter M, may be M|N|Y|O. check for two commas also

match: M1,1,
replace: ,

any help is appreciated

__________________
Rummy
 
Old July 24th, 2008, 12:08 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You haven't specified very clearly, but it looks as if the regular expression you want might be

[MNYO]([0-9]),\1,

Remember that when you are doing a replace, it's perfectly OK to have a regex that matches strings that will never arise, so you could just as well use for example

.([0-9]),\1,

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old July 24th, 2008, 12:27 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

error arises if i use the below statement for $check4 as <AID>M1,1,<AID>M2,2

<xsl:value-of select='replace($check4, "[MNYO]([0-9]),\1,", "")'/>

The numbers will be same at both the positions, i.e, M1,1 and M2,2

 
Old July 24th, 2008, 12:34 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Please try to be a bit more considerate. Doesn't it occur to you that I'm more likely to be able to explain the error to you if you tell me what the error message is?

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old July 24th, 2008, 12:40 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

what is meant is its not giving the needed output.

 
Old July 24th, 2008, 12:51 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Then tell me what output it gives...

(Gosh, this is hard work)

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old July 24th, 2008, 01:06 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

it does not replace anything at all. the replaced text is as such $check4

 
Old July 24th, 2008, 01:38 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You seem to want to do two things, to check whether the value matches "[MNYO]([0-9]),\1,", and if it does, to replace the commas.

So I would suggest

if (matches($check4, '[MNYO]([0-9]),\1,')
then replace($check4, ',', '')
else error()

(or perhaps "else $check4", I don't know)

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old July 24th, 2008, 01:50 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Mike, $check4 will contain M1,N1,. So only i want to replace it.
Let $check4 be &lt;AID&gt;M1,1,&lt;AID&gt;M2,2

The output should be ,
I want to replace M1,1, with just ,
Also 1 will the same at both the places. It will change in he next occurrence as 2 (see $check4 above).

In ($check4, '[MNYO]([0-9]),\1,'), ([0-9]) will check for any number it seems. But I want to check for only 1 at both the positions. At the next occurrence the search will be for 2. I should go one by one only. If I use ([0-9]),\1, the find will go to M2,M1. So only I'm checking for M1,1, especially. I think this might be clear to you now.


 
Old July 24th, 2008, 02:08 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

ok lets try for this condition.

INPUT: M1,N1,
REPLACE: ,

1 will be same at both the positions. It will change as 2 at the next occurrence.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex pendemv JSP Basics 4 December 8th, 2008 08:29 AM
Regex htran XSLT 2 May 18th, 2005 09:21 AM
More regex help Snib Pro PHP 4 December 16th, 2004 09:56 PM
Need RegEx help Snib Pro PHP 6 November 16th, 2004 06:59 AM
Regex Help boyer99g General .NET 2 October 8th, 2004 05:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.