capture text, including tags from string, and then reorder tags with text

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-06-17T19:13:31Z Indexed on 2010/06/17 20:53 UTC
Read the original article Hit count: 191

Filed under:
|

I have the following text:

abcdef<CONVERSION>abcabcabcabc<2007-01-12><name1><2007-01-12>abcabcabcabc<name2><2007-01-11>abcabcabcabc<name3><2007-02-12>abcabcabcabc<name4>abcabcabcabc<2007-03-12><name5><date>abcabcabcabc<name6>

I need to use regular expressions in order to clean the above text:

The basic extraction rule is:

<2007-01-12>abcabcabcabc<name2>

I have no problem extracting this pattern. My issue is that within th text I have malformed sequences: If the text doesn't start with a date, and end with a name my extraction fails. For example, the text above may have several mal formed sequences, such as:

abcabcabcabc<2007-01-12><name1>

Should be:

<2007-01-12>abcabcabcabc<name1>

Is it possible to have a regular expression that would clean the above, prior to extracting my consistent pattern. In short, i need to find all mal formed patterns, and then take the date tag and put it in front of it, as provided in the example above.

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about regex