开发者

How to use multi-line and look-ahead together in Textmate find function with regular expressions?

I've got a XML file and I need to locate all parameters with parameterid named aspect (or name field with Aspect as the value), find the end of the parameter, insert than another similar parameter called linewidth (see below for the aspect parameter

  <parameter>
   <parameterid>aspect</parameterid>
   <name>Aspect</name>
   <valuemin>0.1</valuemin>
   <valuemax>5</valuemax>
   <value>1</value>
  </parameter>

Right now, I can do it with the below code:

(?m:(<name>Aspect<.+?</value>.))(\t+)(</parameter>)

$1$2$3\n$2<parameter>\n$2\t<parameterid>linewidth</parameterid>\n$2\t<name>Line Width</name>\n$2\t<valuemin>0</valuemin>\n$2\t<valuemax>200</valuemax>\n$2\t<value>20</value>\n$2</parameter>

However, I'm pasting all the aspect parameter first. I tried to use (?<= so that I can just find the location of the end of the aspect parameter. But once I do that the (?m: doesn't work. Does anyone know 开发者_运维问答how to make them work together? Just want to know.

Ideally if something like this works would be great:

(?m:(?<=<name>Aspect<.+?</value>.))(\t+)(</parameter>)

Thanx in advance.


Try this regex:

(?m:(<name>Aspect<.+?</value>))(\s+)(</parameter>)

The (\s+) captures both the linefeed and the spaces at the beginning of the next line, so you'll probably want to remove all those \n and \t escapes from the replacement string. The inserted text isn't properly indented, but the regex works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜