Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

capture group - regex

Status
Not open for further replies.

stefanwagner

Programmer
Joined
Oct 19, 2003
Messages
2,373
Location
DE
Well, I searched here without success, and don't get it by reading the java-docs.

I want to split a certain token like this:
<name>groovy</name>
to
<name>
groovy
</name>
(xml-tag, content, xml-tag)

I use string.replaceAll (pattern, matcher) like this:
(the typical hardly readable regex-syntax)
Code:
tmp = tmp.replaceAll ("<([^>]+)>([^<]+)<([^>]+)>", "<\\1>\n\\2\n<\\3>");
the result isn't - as intended - but:
Code:
<1>
2
<3>
The pattern is found, but the backreferences aren't interpreted the way I like.
How would I specify the capturing-group 1, 2, 3 correctly?

seeking a job as java-programmer in Berlin:
 
Found it myself (in JDC Tech Tips):
Code:
tmp = tmp.replaceAll ("<([^>]+)>([^<]+)<([^>]+)>", "<$1>\n$2\n<$3>");
Even after knowing this, I don't find it in the Javadocs...

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top