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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regexp question

Status
Not open for further replies.

yodaa

Programmer
Jun 10, 2004
64
SE
Hi all,

I've tried and tried but I only fail and fail. My problem, a regex query on some XML data.

I have some data

File 1
Code:
<user>
   <username>abcabc</username>
   <name>Yo Daa</name>
   <email>yo.daa@tektips.com</email>
</user>
<customer>
   <name>David Dave</name>
   <email>david.dave@tektips.com</email>
</customer>

File 2
Code:
<user>
   <username>abcabc</username>
   <name>Jake Snake</name>
   <email>jake.snake@tektips.com</email>
</user>
<customer>
   <name>Yo Daa</name>
   <email>yo.daa@tektips.com</email>
</customer>

I wan't to check if these documents contains the name Yo Daa between the <user> </user> tags (File 1 is of interest, not File 2). Have tried several methods with regex with no success. I use JDOM in some of the other procedures in my app, but it is to slow to use in the procedures where I make searches among several XML documents.

I read the files as normal text (FileReader and BufferedReader). I then compile a Pattern and use matches() (Matcher) to find the string combination.

Is there anyone outthere that might have a solution to this problem?
 
Found a solution
Code:
".*?\\<user>.*?(Yo Daa).*?\\</user>.*?"
But now I have a new question. I want to find all documents containing both Yo Daa and Jake Snake.

Using the pattern
Code:
".*?(Yo Daa).*?(Jake Snake).*?"
will NOT give me a match, because my statement requires Yo Daa to be listed before Jake Snake which is not the case.
Using the pattern
Code:
".*?(Jake Snake).*?(Yo Daa).*?"
will give me a match.

How can I make my pattern flag a match no mather the placement of the text in the document?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top