matching and displaying the new values using RegEx and PowerSHell?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ITEngineer
Posts: 188
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Wed Oct 12, 2011 10:52 am

matching and displaying the new values using RegEx and PowerSHell?

Post by ITEngineer »

Hi All,

I need to reformat the value of $ADUser

From: 0123456789
Into: +31 123456789

Without the leading 0 component.

The below snippet is what I have come up with, but it is still not working with the RegEx section to segregate the 0 section.

Code: Select all

$ADUser = '0123456789'

$(If ($ADUser) {
        If ($ADUser.ToString() -match '^([\+|0-9 ][ 0-9.]{1,12})$')
        { "+31 $($Matches['^([\+|0-9 ][ 0-9.]{1,12})$'])" }
        Else
        { $ADUser.ToString() }
    }
    Else { $ADUser.ToString() })
Any help would be greatly appreciated.

Thanks in advance,
/* IT Engineer */

jvierra
Posts: 14228
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: matching and displaying the new values using RegEx and PowerSHell?

Post by jvierra »

Why so much code:

'+31 ' + '0123456789' -replace '^0'

User avatar
ITEngineer
Posts: 188
Joined: Wed Oct 12, 2011 10:52 am

Re: matching and displaying the new values using RegEx and PowerSHell?

Post by ITEngineer »

jvierra wrote:
Wed Nov 28, 2018 6:46 pm
Why so much code:

'+31 ' + '0123456789' -replace '^0'
Yes, that works really well :)

This is part of the email signature script that I am working on.

Thanks for the suggestion Mr. Vierra
/* IT Engineer */

Locked