regex help

Hi Experts,

My old nemesis, regex.  What i want to do is get a vm name out a string and replace it with a new name. When i'm renaming the VM i have to rename all the hard disks etc

e.g.

currentvm = vm1

c:\clusterstorage\vhd\VM1.vhdx
c:\clusterstorage\vhd\VM1-001.vhdx
c:\clusterstorage\vhd\VM1-002.vhdx

newvm = vm2

c:\clusterstorage\vhd\VM2.vhdx
c:\clusterstorage\vhd\VM2-001.vhdx
c:\clusterstorage\vhd\VM2-002.vhdx
cmatchettAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
What language?  Do you really need REGEX (feels like overkill for this), seems like a SUBSTITUTE() or REPLACE() might be enough, just looking for "\VM1" and replacing with "\VM2".


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cmatchettAuthor Commented:
language is powershell
0
cmatchettAuthor Commented:
$currentvm = 'vm1'

$newvm = 'vm2'

$String1 = 'c:\clusterstorage\vhd\VM1.vhdx'

$String1.replace("$currentvm","$newvm")

$String1

this didn't work
0
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

cmatchettAuthor Commented:
It's case sensitive

$currentvm = 'VM1'

$newvm = 'vm2'

$String1 = 'c:\clusterstorage\vhd\VM1.vhdx'

$String1.replace("$currentvm","$newvm")

$String1

c:\clusterstorage\vhd\vm2.vhdx
c:\clusterstorage\vhd\VM1.vhdx

need a solution thats not case sensitive
0
cmatchettAuthor Commented:
This is not case sensitive

$currentvm = 'VM1'

$newvm = 'vm2'

$String1 = 'c:\clusterstorage\vhd\VM1.vhdx'

$String1 -replace $currentvm, $newvm

is there a better way?
0
Bill PrewIT / Software Engineering ConsultantCommented:
That last one seems like the best approach to me, probably the lightest weight option.


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.