-1

so i dont have any idea how do i write such program ..please help...

so i want to write a program in java which reads the text between two strings

like i the full text is

             <name> XYZ </name>

so here i want to read the XYZ which can be anything i need the code so that it matches

        <name> ---- </name> and fetch the string in between them 

and save it to a string..

please help me on this ..i dont know where to start..

i think i need to use regular expresion that matches the pattern

            <name>  </name>

but dont know how to do that....please suggest.........

Klemens Morbe
  • 595
  • 9
  • 24
roanjain
  • 1,252
  • 4
  • 14
  • 32

1 Answers1

0
import java.util.regex.*;

final Pattern p = Pattern.compile("<name>(.+?)</name>");
final Matcher m = p.matcher("<name>any string you want to retrieve</name>");
m.find();
System.out.println(m.group(1));

then you can assign your matcher result to a String for further processing.

ludo_rj
  • 3,877
  • 1
  • 18
  • 37