Solved

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

Posted on 2014-09-11
3
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

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

test1234*
then  return test1234
0
 
LVL 50

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 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