views:

40

answers:

3

Is it possible to use regex to turn this

<site-ui:header title="error" backURL="javascript:history.go(-1);" />

into this

<site-ui:header 
  backURL="javascript:history.go(-1);" 
  title="error" 
/>

Basically, my goal is to format this xml so that the fields are in alphabetical order (e.g. backURL comes before title), and each field should be tabbed two spaces.

If this can be done, any pointers would be really helpful! Even more helpful is an exact regex for vim.

A: 

Not completely sure, my knowledge of regex and its capabilities is small. But here is a tool that has always helped me!

http://xenon.stanford.edu/~xusch/regexp/analyzer.html

Meiscooldude
+1  A: 

Sounds more like a job for xslt/xsd or a custom parser with a handful of regexes and other string manipulations.

A single regex isn't going to do it. Especially the alphabetizing part

Doing it with a Vim macro or script is most likely possible, but beyond my meager vim powers.

BioBuckyBall
Thanks, that's all I needed to know
Sam
+1  A: 

These simple substitutions should do the job, except for the sorting:

:%s/ title=/^V^M  title=/g
:%s/ backURL=/^V^M  backURL=/g

Note that ^V^M above is a literal ^V^M.

Ether