Regular expression for XML tag

72 Views Asked by At

I am having a hard time matching the following text:

<Reports>
   <Report active="1" valid="1" bureau="EXS"> Dummy Dummy</Report>
</Reports>

Using the following Regex:

/<Reports>.*<\/Reports>/

I am using rubular (I am using ruby) to test it , but I don't understand why my RegEx fails.

http://rubular.com/r/QEhgQ9Vgla

Any help?

2

There are 2 best solutions below

0
On BEST ANSWER

You need to include multiline modifier m.

/<Reports>.*<\/Reports>/m

DEMO

0
On

You could solve the problem with the help of REXML library.

require 'rexml/document.rb'

doc = REXML::Document.new <<-DOC
<Reports>
   <Report active="1" valid="1" bureau="EXS"> Dummy Dummy</Report>
</Reports>
DOC

doc.get_text("/Reports/Report") # => " Dummy Dummy"