0

I am trying to create a pattern for matching and replacing the words using regex. My string is like given below

<mycomponent id="Myvalue1.Myvalue2.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9"
<mycomponent id="Myvalue3.Myvalue4.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9"
<mycomponent id="Myvalue5.Myvalue6.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9"
<mycomponent id="Myvalue7.Myvalue8.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9"

I want the expected result to be look like

<mycomponent id="Myvalue1.Myvalue2"
<mycomponent id="Myvalue3.Myvalue4"
<mycomponent id="Myvalue5.Myvalue6"
<mycomponent id="Myvalue7.Myvalue8"

I can't use ReplaceAll .013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9 to empty because there are some features that are still using that GUID

I was able to match the string using below pattern

  <mycomponent Id=*.*.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9

But when i used the below pattern for replacing it is not working

 <mycomponent Id=*.*.
2
  • what programming language is used in your case? Commented Jul 28, 2016 at 20:12
  • i am trying to replace value using Notepad++. Commented Jul 28, 2016 at 20:12

2 Answers 2

1

That pattern doesn't really do the intended thing, since you haven't escaped the dots. That's just a coincidence. To match what you want, the following regex should be used.

<mycomponent id=.*?\..*?\.

This regex matches <mycomponent id=, then a dot, then the minimal amount of chars before it meets a dot, then a dot, then again the minimal amount of chars before it meets another dot.


If you would like to repalce, use this for the regex field

(<mycomponent id=".*?\..*?)\.\S+

and this for the replace field

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

9 Comments

and for replacing what regex should i use
@user What would you like to replace, and with what?
it is mentioned in the question.Could you please look that
@user It isn't. You just said that you're not going to remove the ids with replaceAll.
@user Do you want to remove the GUID or <mycomponent id=Myvalue1.Myvalue2?
|
1

Use the following approach:

  • regexp field(search for):

    (<mycomponent id=.+\..+)(?:\.)013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9(.+)
    
  • replace to:

    $1$2
    

(tested on Notepad++)

5 Comments

It is working. But i just want to replace the GUILD. This pattern is replacing everything after the GUID too.
you have not presented the actual string which contain something after the GUID. Add some example
My full string is like <mycomponent id=Myvalue1.Myvalue2.013D0E13-BF5F-4D0F-AAFA-FA4B120DE3E9 Name="test.DLL" Path="nil" verbose="no">
I doubt OP has the same GUID everywhere. This solution is not really flexible.
Yes Nicael,GUID is same everywhere

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.