Powershell replace email suffix

I'm trying to write a small script that prompts users for their email address. The value of this email gets passed to a function which will replace their email suffix such as .net, .com, .edu to .org. I have the following code, but it's not replacing the suffix. Any help in this matter would be appreciated. Thank you.

$mail = Read-Host "Please enter your email address"

Function Email ($change)
    $modified=$change.Replace(".{3}[A-Za-z]", ".org")

Email $mail


You are using String.Replace which doesn't work with regex.

Also, your regex doesn't do what you want it to do.

. is a special character in regex and you want to escape it. Also the {3} should be after the character class.

Try the below:

Function Email ($change)
    $modified=$change -replace "\.[a-zA-Z]{3}$", ".org"

The $ indicates end of string.

PS: If you are not validating input ( through regex match, you can as well use substring to replace to org)

Need Your Help

Improve performance ng-repeat list 750 elements

angularjs performance ng-repeat

wanna know the best way to improve performance in my scenario a list of 750 elements filtered in real time and with the requirement of no pagination or limit the list, the 750 elements should be on

Difficulties in converting an recursive algorithm into an iterative one

javascript algorithm recursion maze

I've been trying to implement a recursive backtracking maze generation algorithm in javascript. These were done after reading a great series of posts on the topic here

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.