Solved

regular expression replaceif the thereis a non alpha numeric charters at the end of the string

Posted on 2014-09-11
3
194 Views
Last Modified: 2014-09-15
I wnat to replace with empty string if there is an apha numeric character at the end of the string
0
Comment
Question by:Angela4eva
3 Comments
 

Author Comment

by:Angela4eva
ID: 40317496
I want to replace that chacters only

test1234*
then  return test1234
0
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 40318837
Hi,

pls try

"test1234*".Replace("\W$", "");

Regards
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 40320397
@Rgonzo1971's solution allows underscore characters to remain at the end of the string. It also only removes the last non-alphanumeric character when there are more than one. To fix both those issues, use:
"test1234*".Replace("[^a-zA-Z0-9]+$", "");

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now