# Regex replace

**URL:** <https://forums.powershell.org/t/regex-replace/8772>\
**Category:** PowerShell Help\
**Created:** [June 6, 2017, 9:52am UTC](https://forums.powershell.org/t/regex-replace/8772 "2017-06-06T09:52:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kishor](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@kishor](https://forums.powershell.org/u/kishor)\
**Post date:** [June 6, 2017, 9:52am UTC](https://forums.powershell.org/t/regex-replace/8772/1 "2017-06-06T09:52:17Z")

</div>

Hi,  
When I type below command the new value is appended to the existing value;  
(Get-Content C:\temp\File.ini) -replace ‘IP\_1=\*’, (‘IP\_1=’+$ip) | Set-Content c:\temp\File.Ini

And when I add a period to the old character value ‘IP\_1=.\*’ the old value is replaced totally, wanted to know how does period work here?

Thanks,  
Kishor

---

<div class="post-metadata">

**Author:** ![chrisp](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@chrisp](https://forums.powershell.org/u/chrisp)\
**Post date:** [June 6, 2017, 9:58am UTC](https://forums.powershell.org/t/regex-replace/8772/2 "2017-06-06T09:58:23Z")

</div>

Is it trying to dot source the file? I can’t be sure, but that’s perhaps what its doing, look at

[http://www.computerperformance.co.uk/powershell/powershell\_syntax.htm#Operators\_](http://www.computerperformance.co.uk/powershell/powershell_syntax.htm#Operators_)

Its also used for objects, so maybe it’s doing something funky? Sorry i couldn’t be more help.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 6, 2017, 11:54am UTC](https://forums.powershell.org/t/regex-replace/8772/3 "2017-06-06T11:54:25Z")

</div>

**-replace** works with [regular expressions](https://en.wikipedia.org/wiki/Regular_expression). A period is the meta charachter for “any charachter” and the star/asterisk (\*) is the modifier meaning 0 or any number of occurances of the charachter or meta charachter or group right before this meta charachter.

What is it, what you’re trying to accomplish?

---

<div class="post-metadata">

**Author:** ![kishor](https://avatars.discourse-cdn.com/v4/letter/k/8edcca/32.png) [@kishor](https://forums.powershell.org/u/kishor)\
**Post date:** [June 7, 2017, 1:40am UTC](https://forums.powershell.org/t/regex-replace/8772/4 "2017-06-07T01:40:28Z")

</div>

Thank you Olaf and Chris.  
I am using the command to modify an IP address in the ini file IP\_1 = x.x.x.x to IP\_1 = y.y.y.y

Thanks,  
Kishor

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [June 7, 2017, 2:51am UTC](https://forums.powershell.org/t/regex-replace/8772/5 "2017-06-07T02:51:37Z")

</div>

If you’re looking for literal periods with regex you have to “escape” them with a backslash … like this “ **.** ”

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/regex-replace/8772/6 "2024-05-16T20:38:40Z")

</div>

Closed on May 16, 2024, 8:38pm UTC


