Regex

Asked

Viewed 87 times

0

Good morning. I have an XML that contains a node as follows:

 <endnum>76 AP 10 404</endnum>
 <endnum>404</endnum>

It turns out that this value should only be integer, as in the second example, but some contain letters. I would like to locate all nodes of that field containing letter to replace with <endnum>0</endnum>. I tried to use Regex and I wasn’t happy. Someone would know to tell me a solution?

1 answer

3

Whereas valid values only have numbers, you need only search for the existence of non-digits (\D) within that tag: <endnum>.*?\D.*?<\/endnum>. Then just put the tags in capture groups: (<endnum>).*?\D.*?(<\/endnum>) and replace with $10$2.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.