in reply to Re: replace string
in thread replace string
I think this is a better regex to solve this problem:
s!\s*<\s*(/?)\s*(\w+)\s*>\s*!$1?"\n":"\n\{$2\}\n"!ge;
because </ttl> should not appear (from the example's output) and there is a problem with extra white spaces surrounding and inside tags. Also, there was no info on what to do if there is more text after a closing tag, so I guessed that a new line must be inserted.
But that regex will generate extra empty lines if a data line starts with a tag. Changing to this should do the trick:
s!\s*<\s*(/?)\s*(\w+)\s*>\s*!$1?"\n":"\n\{$2\}\n"!ge and s!^\n!!;
Please note that I kept the \w+ for the capture, asuming that only alphanumerics are admited as tags.
|
|---|