Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extracting attribute value in XML using regex

Tags:

java

regex

groovy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE ... ]> 
<abc-config version="THIS" id="abc">
...
</abc-config>

Hi all,

In the code above, how can I extract the value of version attribute using Regex in Groovy/Java?

Thanks.

like image 744
minirasher Avatar asked May 08 '26 18:05

minirasher


1 Answers

A regex to handle this could be something like:

/<\?xml version="([0-9.]+)"/

I'll spare you one of the 10000 lectures about not using a regex to parse markup languages.

Edit: The One whose Name cannot be expressed in the Basic Multilingual Plane, He compelled me.

like image 123
CanSpice Avatar answered May 11 '26 13:05

CanSpice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!