matching and displaying the new values using RegEx and PowerSHell?

Ask your 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.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post by ITEngineer »

jvierra wrote: Wed Nov 28, 2018 5: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 */
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked