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

  • Home
  • SEARCH
  • 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 8027155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:43:51+00:00 2026-06-04T23:43:51+00:00

I need to match text which has @ , # , and any number

  • 0

I need to match text which has @, #, and any number in it. The characters can be in random position as long as they are in the text. Given this input:

abc@#d9
a9b#c@d
@@abc#9
abc9d@@
a#b#c@d

The regex should match the first 3 lines. Currently my regex is:

/@.*?#.*?[0-9]/

Which doesn’t work since it will only match the three chars in sequence. How to match the three chars in random order?

  • 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-06-04T23:43:52+00:00Added an answer on June 4, 2026 at 11:43 pm

    Found one of this ugly regex, if you really must use one:

    /(?=.*@)(?=.*#)(?=.*[0-9]).*/

    http://jsfiddle.net/BP53f/2/

    The regex is basically using what they call lookahead

    http://www.regular-expressions.info/lookaround.html

    A simple case from the link above is trying to match q, followed by u, by doing q(?=u), that’s why it’s called lookahead, it finds q followed by u ahead.

    Let’s take one of your valid case: a9b#c@d

    The first lookahead is (?=.*@), which states: Match anything, followed by a @. So it does, which is the string a9b#c, then since the match from the lookahead must be discarded, the engine steps back to the start of the string, which is an a. Then it goes to

    (?=.*#), which states: Match anything that is followed by #, then it finds it at a9b. etc. The difference between using lookahead and (a)(b)(c) is basically the stepping back.

    From the link above:

    Let’s take one more look inside, to make sure you understand the
    implications of the lookahead. Let’s apply q(?=u)i to quit. I have
    made the lookahead positive, and put a token after it. Again, q
    matches q and u matches u. Again, the match from the lookahead must be
    discarded
    , so the engine steps back from i in the string to u. The
    lookahead was successful, so the engine continues with i. But i cannot
    match u. So this match attempt fails. All remaining attempts will fail
    as well, because there are no more q’s in the string.

    It is ugly because it’s difficult to maintain… You basically have 3 different sub-regex inside the brackets.

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

Sidebar

Related Questions

I need to make a version of the function subRegex which works with Text.Regex.PCRE
I have a requirement where I need to match text like testuser or joeperson
I have a fairly large text file from which I need to extrapolate a
Here is the setup: dynamically generates content for a number of items which need
I have text files which I need to remove stop words from them. I
To match string, which contains some word, I can use pattern /.*word.*/. But how
I need to perform a search/replace on text which contains a comma which is
Visual Studio 2010 has a new feature that is just way cool. You can
Ok, so I know this question has been asked in different forms several times,
I have some XML files of this form: <?xml version=1.0 encoding=utf-8?> <?xml-stylesheet type=text/xsl href=biomirror.xsl?>

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.