Two Laptop Bag
The moose likes Java in General and the fly likes string extraction pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "string extraction pattern" Watch "string extraction pattern" New topic
Author

string extraction pattern

Mahesh Murugaiyan
Greenhorn

Joined: Jun 25, 2009
Posts: 21
Hi,

I have a xml with list of users and need to extract names from the xml. i want to do this using groups, but not getting the right one. (needless to say, i am just beginning to explore the regex world ).
i have given the xml below. and trying this: Pattern.compile("(<name>(.*)</name>)",Pattern.CASE_INSENSITIVE ); which displays the whole string..
any suggestion will be of great help.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<listUsers>
<user>
<id>001</id>
<name>blah1</name>
<desc>blah desc</desc>
</user>
<user>
<id>002</id>
<name>blah2</name>
<desc>blah desc</desc>
</user>
<user>
<id>003</id>
<name>blah3</name>
<desc>blah desc</desc>
</user>
<listUsers>
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16695
    
  19

It may be a good idea to make group reluctant -- ie ".*?" -- or it will grab everything from the first <name> to the last </name>.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string extraction pattern
 
Similar Threads
how to use spaced column names in hibernate orderby mapping xml
Data not get displayed in struts2 - jquery grid
CDATA
how to put a counter in XSL
Is there a simple way to do JDK 5 enumerations in Hibernate?