Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-09-11
3
Medium Priority
?
235 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 53

Expert Comment

by:Rgonzo1971
ID: 40318837
Hi,

pls try

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

Regards
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

963 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