bharal
bharal

Reputation: 16174

Regex backreference and Intellij

I am using Intellij.

I have this xml:

...
<ml:comment />
<ml:pohpoh>
...

and i want to make it look like this:

...
<ml:comment />
<ml:dodo>Volvo</ml:dodo>
<ml:pohpoh>
....

but there is a lot of it, so i wanted to use the replace in path feature.

However, this doesn't work (i am trying a single relpace-in-file before I replace all in the path!)

Find:

ml:comment />[\n].*<ml:[^dodo]

Replace:

ml:comment />\$1.*<ml:dodo>Volvo</ml:dodo>\n\$2

Also ~ I am concerned the right number of spaces won't be put in, how would i capture all those spaces?

Upvotes: 1

Views: 1087

Answers (2)

OGHaza
OGHaza

Reputation: 4795

Find:

(<ml:comment\s*/>)(\s*)(?!<ml:dodo)

Replace:

$1$2<ml:dodo>Volvo</ml:dodo>$2

This should maintain indentation which I assume is what you were worried about in terms of losing whitespace.

Working example on RegExr

Upvotes: 7

user557597
user557597

Reputation:

So you want to find/replace
(<ml:comment\s*/>)\s*<(?!ml:dodo) ,
$1\n<ml:dodo>Volvo</ml:dodo>\n< ?

Upvotes: 3

Related Questions