Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6766405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:49:36+00:00 2026-05-26T14:49:36+00:00

I have a situation.. Having a string which can contain numbers,letters, and some symbols,

  • 0

I have a situation..
Having a string which can contain numbers,letters, and some symbols, I want to make an extraction from it or to make some replacements based on some “rules”.
I thing the best is to give some examples of possible situations and what I want to do (display):

String           Display1   or  Display2

AB_X345           X345         or  ###X345  
AB_1234            1234        or  ###1234  
X987_TEXT_4567    X9874567     or  X987######4567  
X987TEXT4567      X9874567     or  X987####4567  
X798TEXT          X798         or  X798####  
789TEXT            789         or  789####  
X400              X400         or  X400   

So practically when I find an X followed by numbers I want to display them. If some text appear, I don’t want it displayed or I want it masked with a character(#).
In case no X is present, I want to display only the numbers.
Is Regex the easyest way of doing this? (I am not familiar with regex-just had a bird’s eye view on it).
Can all the rules be gathered in a single regex expression or is to complicated?

Thank you for any sugestions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:49:36+00:00Added an answer on May 26, 2026 at 2:49 pm

    That’s easy:

    resultString = Regex.Replace(subjectString, 
        @"\D       # Match a non-digit character
        (?<!       # unless...
         X         #  it's an X
         (?=\d)    #  which is followed by a digit.
        )          # End of lookbehind", 
        "", RegexOptions.IgnorePatternWhitespace);
    

    Change the last line to

        "#", RegexOptions.IgnorePatternWhitespace);
    

    to mask the characters with # instead of removing them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have situation in which I read a record from a database. And if
I have a situation in which a managed DLL calls some unmanaged DLL. I
I have a fixed string S of size n on which I make a
I'am having the following situation. We have a private method where I want to
I tried endlessly now you resolve this utter frustrating situation I have been having.
I have situation where a user can manipulate a large set of data (presented
I have some code I inherited which has a lot of warnings that I
My situation is simple: I have some records in my core data store. One
I have a .net web service that takes some xml data. From within the
I've been having some success with JQGrid but I'm now in a situation where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.