0

Hi i am trying to write a regular expression for matching and replacing below strings using Notepad++

<mycomponent id="Myvalue1.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9" test="my" value="1234"/>
<mycomponent id="Myvalue3.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9" kv="ggg" propert="null"/>
<mycomponent id="Myvalue5.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9" fff="ddd" key="kk"/>
<mycomponent id="Myvalue7.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9" dfd="drgf"/>

I want to replace 013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9 from these string and result should be as given below

  <mycomponent id="Myvalue1" test="my" value="1234"/>
 <mycomponent id="Myvalue3" kv="ggg" propert="null"/>
   <mycomponent id="Myvalue5" fff="ddd" key="kk"/>
<mycomponent id="Myvalue7" dfd="drgf"/>

I used the below RE for matching and replacing

(<mycomponent id=".*?\.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9)\S+ 

as the find sting and $1 as the replace string. Eventhought the find is working the replace is not working

8
  • Hello Nicael. What i tried is given in the question. Could you please tell me what is wrong Commented Jul 29, 2016 at 6:43
  • Is it an XML document with valid XML structure? Commented Jul 29, 2016 at 6:46
  • It's really basically the same as I've mentioned in my previous answer. Just remove the first .*?\. and you have this question answered. Commented Jul 29, 2016 at 6:46
  • yes its an xml document Commented Jul 29, 2016 at 6:49
  • 1
    But you should use the same $1", while you're using $1. Commented Jul 29, 2016 at 6:55

1 Answer 1

2

Find What: (<mycomponent.*?)[.]013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9

Replace with : $1

search mode : Regular Expression

It will also work for this question

And if you want to make it more general for other unique identifiers:

Find What: (<mycomponent.*?id="[^"]*?)[.][A-Fa-f0-9\-]{36}
Replace with : $1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.