2

My script should look for a comma separated 3 digit version number (eg. 1.2.3)
and replace it with the new version number. The same file has another string which doesnt meet this regex still the script changes it.

Samplefile.txt

  "[email protected]"
  "e2bf8da9-275a-484d-95a6-7e6b8c0ce0ca"

Replace command portion from the Script:

  -replace "\d.\d.\d","2.2.2"

I expect it to give output like this,

  "[email protected]"
  "e2bf8da9-275a-484d-95a6-7e6b8c0ce0ca" # This string not changed

But it changes the second string too as follows which I didn't intent to

   e2bf8da2.2.2a-484d-92.2.2e2.2.2ce0ca

Am I wriitng the regex all wrong. Can someone help please?

1
  • The "dot" (aka period .) in a regex is the match-anything meta-character, so \d.\d.\d matches "a digit followed by any character followed by a digit followed by any character followed by a digit". See Kasra's answer for making the dot a plain dot. Commented May 29, 2015 at 22:02

1 Answer 1

1

You need to escape the dots in your regex :

"\d\.\d\.\d"

Demo

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.