• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

string extraction pattern

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic