JonnyIrving
JonnyIrving

Reputation: 753

Java RegEx Replace all to format data from XML

Good afternoon all,

I've noticed they're a few similar problems on here already but non have been of much help to me so far. I am trying to manipulate a String returned by and existing method to format it in to a readable form. So for example I am trying to creates a String replaceAll() regular expression which will take the string

"<ds:AddressLine1>Birkmire Farm</ds:AddressLine1><ds:AddressLine2>Some Village</ds:AddressLine2><ds:AddressLine3>Wigfield</ds:AddressLine3><ds:AddressLine4>Cumbria</ds:AddressLine4><ds:UKpostcode>CA9 1EJ</ds:UKpostcode>"

and convert it to...

Birkmire Farm, Some Village, Wigfield, Cumbria, CA9 1EJ

The way I envisaged doing this was in three steps, firstly to replace all the closing tags with "", then to replace all the opening tags with ", " and finally use the String replaceFirst to remove the first comma and space placed at the front of the string.

The issue I am having is the RegEx I need to formulate a pattern to identify any opening tag ie and a pattern to identify any closing tag ie . Any help on this would be greatly appreciated.

Upvotes: 0

Views: 986

Answers (1)

Rob I
Rob I

Reputation: 5737

RE for opening tag: <[^/][^>]*>. RE for closing tag: </[^>]*>.

Upvotes: 1

Related Questions