Hi folks,

resending this just in case someone has a clue (a similar question
involving backreferences on substitutions surfaced a couple of days
ago). Just to clarify a little further:

if I execute

RE regexp = new RE("<([:alnum:]+)[^>]*>([^<]*)</\1>",  RE.MATCH_CASEINDEPENDENT | 
RE.MATCH_MULTILINE);
System.out.println(regexp.subst("<tag1>this text</tag1> should <tag2>remain 
untouched</tag2>", "\2", RE.REPLACE_ALL));

I would expect to see text with tags removed, since backref \1 would
match against each tag, and \2 would match with text between tags.
Instead, I see

 should 

(with one space before and another after)

The funny thing is that regexp.getParen(1) equals "tag1", and
regexp.getParen(2) equals "this text". The result above (" should "),
however, is nowhere close to what I would expect.

Is there anyway to do what I want?

TIA

Andre

---------- Begin forwarded message: ----------

Date: Mon, 2 Jun 2003 20:48:28 -0300
From: Andre Costa <[EMAIL PROTECTED]>
To: REGEXP user ML <[EMAIL PROTECTED]>
Subject: Backreferences on substitution?


Hi all,

it seems the archives are unreachable, so I will fire this question
without having first searched for an existing answer... please bear with
newbie ignorance ;)

Is it possible to specify backreferences on substitution patterns? The
probl is: I would like to get rid of some tags but leave their content
untouched. This pattern correctly catches data on the form
<tag ...>data</tag>:

<([:alpha:]+)[^>]*>([^<]*)</\1>

However, if I want to use it on a text where it appears multiple times
with RE.subst(), how do I pass a backreference to the second capture to
the 'substitution' parameter? For example, this text

<tag1>this text</tag1> should <tag2>remain untouched</tag2>

should become

this text should remain untouched

Any clues? What am I missing?

TIA

Andre

-- 
Andre Oliveira da Costa

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------- End of forwarded message ----------

-- 
Andre Oliveira da Costa

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to