• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regex construction problem

 
Charles Knell
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write a class that will pull an XML document out of a text file with surrounding junk. As a first step, I cribbed some code from another web site and so far I have this:



As you can see, I dummied up a string for testing purposes. Later I'll read the content of the file into a string for which this is now a placeholder.

The regex doesn't match, and I can't figure out why. I double-escaped the question marks in the regex pattern, what else am I missing?

Thanks.
 
Henry Wong
author
Sheriff
Posts: 22530
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try...



Henry
 
Charles Knell
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. So my problem was that I didn't escape the "." in "1.0" and I needed to expand the match from "." to ".*" in ">.*</rowset>". Did I understand correctly?
 
Henry Wong
author
Sheriff
Posts: 22530
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Charles Knell:
Thanks. So my problem was that I didn't escape the "." in "1.0" and I needed to expand the match from "." to ".*" in ">.*</rowset>". Did I understand correctly?


Well, those are the two obvious changes that you need to match the string in your example (although one of those changes is technically not needed). However, I have *not* tested it, so I may have missed something.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!