Regular expressions are sometimes used on text that spans multiple lines, which Groovy has support for. I had to search for how to enable multi-line searching, so I thought it would be good to post here.
To allow the expression to span multiple lines we can add (?ms)
to the beginning of the expression.
Take the following example, where want to grab the entire book
element from a single-line XML document:
def xml = "<library><book><title>Effective Java</title><author>Bloch</author></book></library>"
def matcher = xml =~ /<book>.*<\/book>/
matcher.size() > 0 ? matcher[0] : "NOTHING"
This gives us an entire book
:
<book><title>Effective Java<title><author>Bloch<author><book>
If the XML was to span multiple lines however, we end up with NOTHING
:
def xml = """<library>
<book>
<title>Effective Java</title>
<author>Bloch</author>
</book>
</library>"""
def matcher = xml =~ /<book>.*<\/book>/
matcher.size() > 0 ? matcher[0] : "NOTHING"
Now if we add the (?ms)
, we will still get an entire book
entry:
def xml = """<library>
<book>
<title>Effective Java</title>
<author>Bloch</author>
</book>
</library>"""
def matcher = xml =~ /(?ms)<book>.*<\/book>/
matcher.size() > 0 ? matcher[0] : "NOTHING"
The above results in:
<book>
<title>Effective Java<title>
<author>Bloch<author>
<book>
If you have any other tips or another way to accomplish the same thing, please feel free to leave a comment.
THANK YOU SO MUCH
ReplyDeleteEXACTLY WHAT I WAS LOOKING FOR
Thanks for providing the best information it's very useful sap basis learners.
ReplyDeleteSAP BASIS Course in Hyderabad
Online SAP BASIS Training in USA
Yes ,
ReplyDeleteThis is interesting blog and valuable blog.thanks for sharing such a important blog.
oracle fusion procurement online training
I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor
ReplyDeletelead live training in Oracle Fusion Financials online Training , World Class Virtual Instructor led training on Oracle fusion Financials Training. We have industry expert trainer. We provide Training Material and Software Support. calfre has successfully conducted 100000+ trainings in India, USA, UK, Australlia,
Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
You're so interesting and Fantastic; so nice to find someone with some original thoughts on this subject seriously........................Erptree Oracle Training Institute.
ReplyDelete
ReplyDeleteI am overwhelmed by your post with such a nice topic. Usually, I visit your blogs and get updated with the information you include but today’s blog would be the most appreciable...
Thanks
Cpa offers
For Data Science training in Bangalore, Visit:
ReplyDeleteData Science courses in Bangalore
Hiiii...Thanks for sharing great info...Nice post...Keep move on...
ReplyDeleteBlockchain Training in Hyderabad
thanks for sharing nice information -------
ReplyDeletemore : http://opensourcetechnologies.in/blockchain-training-in-hyderabad
I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing.
ReplyDeleteBecame an Expert In Google Cloud Platform Training in Bangalore! Learn from experienced Trainers and get the knowledge to crack a coding interview, @Softgen Infotech Located in BTM Layout.
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.Real Time Experts Training in Bangalore
ReplyDeleteNice Blog.
ReplyDeleteThanks for sharing.
We help IT professionals by providing them Best Online Job Support in 250+ technologies. Our services are very reliable and most affordable. Call Today for free demo.
Great Share!!!Java concepts are really Amazing...Explanation's are make me to clear all my doubts...Big Thanks for your effective works...
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
It's wonderful article. Nice content.
ReplyDeletePython Training in Chennai
Python Training in Bangalore
Python Training in Hyderabad
Python Training in Coimbatore
Python Training
Your blog is really very informative and unique. Keep posting like this. Awaiting for your further update.
ReplyDeleteWeb Designing Training in Chennai
Web Designing Course in Chennai
Web Designing Training in Bangalore
Web Designing Course in Bangalore
Web Designing Training in Hyderabad
Web Designing Course in Hyderabad
Web Designing Training in Coimbatore
Web Designing Training
Web Designing Online Training
perfect explanation about java programming .its very useful.thanks for your valuable information..
ReplyDeletedata science training in chennai
data science training in omr
android training in chennai
android training in omr
devops training in chennai
devops training in omr
artificial intelligence training in chennai
artificial intelligence training in omr
Wonderful article, very useful and well explanation. Your post is extremely incredible. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
ReplyDeleteJava Training in Chennai
Java Training in Velachery
Java Training inTambaram
Java Training in Porur
Java Training in Omr
Java Training in Annanagar
Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog.
ReplyDeleteDigital Marketing Training in Velachery
Digital Marketing Training in Tambaram
Digital Marketing Training in Porur
Digital Marketing Training in Omr
Digital MarketingTraining in Annanagar
Great Articles...Thanks for sharing your articles,Keep doing this....
ReplyDeleteSoftware Testing Training in Chennai
Software Testing Training in Velachery
Software Testing Training in Tambaram
Software Testing Training in Porur
Software Testing Training in Omr
Software Testing Training in Annanagar
This is a fantastic idea! I like it a lot because it's super easy for the audience to see the value of opting in. wonderful and amazing post very use full your post thanks for sharing your article
ReplyDeleteDevOps Training in Chennai
DevOps Course in Chennai
Excellent blog and I really glad to visit your post. Keep continuing...
ReplyDeleteinternship meaning | internship meaning in tamil | internship work from home | internship certificate format | internship for students | internship letter | Internship completion certificate | internship program | internship certificate online | internship graphic design
thanks for assisting human beings income the information they mannerism. brilliant stuff as pleasing. preserve up the massive take feature!!!! https://cyberspc.com/tally-erp-9-crack/
ReplyDeleteLovely site blog its wonderful.
ReplyDeleteFreemake Video Converter Key
Vsdc Pro Crack
Driver Updator Key
Flixgrab Activation Key
Excellent blog and I really glad to visit your post. Keep continuing...
ReplyDeleteEmbedded Systems Course in Hyderabad
Good content. You write beautiful things.
ReplyDeletevbet
taksi
hacklink
mrbahis
korsan taksi
hacklink
mrbahis
vbet
sportsbet
Success Write content success. Thanks.
ReplyDeletekralbet
betmatik
deneme bonusu
canlı slot siteleri
betpark
betturkey
canlı poker siteleri
شركة مكافحة حشرات بالقصيم
ReplyDeleteشركة مكافحة حشرات بالاحساء
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
D7WOF
This comment has been removed by a blog administrator. our sclinbio.com
ReplyDeleteThis is the good website and also i love this website https://sclinbio.com
ReplyDeleteشركة صيانة افران بجازان qcBzcSDYuD
ReplyDelete