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 7539715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:27:20+00:00 2026-05-30T07:27:20+00:00

I need a regex to match a word that starts with #. I wrote

  • 0

I need a regex to match a word that starts with #.

I wrote this question How to match a pound (#) symbol in a regex in php (for hashtags), but I forgot to explain that I need the # at the beginning of a word.

I need to match #word, #123, #12_sdas, but not 1#234 or #1234.

For example, in "#match1 notMatch not#Match #match2 notMatch #match3", only #match1, #match2 and #match3 should appear.

Edit: I just want one pound (#), followed by one or more [a-ZA-Z0-9_]. The match can’t have any of [a-ZA-Z0-9_] before.

My problem was finding the pound at the beginning of the word.

  • 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-30T07:27:21+00:00Added an answer on May 30, 2026 at 7:27 am

    Try this:

    preg_match_all('/(?:^|\s+)(#\w+)/', $your_input, $your_results);
    // print results
    print_r($your_results);
    

    It will match all words beginning with a # symbol. Words can be sepearted by all valid whitespace characters (so one of \t\r\n\v\f)

    Example

    //input
    #match1 notMatch not#Match #match2 notMatch #match3
    //output
    Array
    (
        [0] => Array
            (
                [0] => #match1
                [1] =>  #match2
                [2] =>  #match3
            )
    
        [1] => Array
            (
                [0] => #match1
                [1] => #match2
                [2] => #match3
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regex that will match blahfooblah but not blahfoobarblah I want it
I need regex that will match this Fred, Jhon, Tree, and there could be
I need to build a regex (in PHP) that match if a string has
i need a regex that matches an expression ending with a word boundary, but
I need some help. I am looking for a regex that would match the
I need to match Safari browsers, but not Chrome browsers using one Regex. I
^(.)+\S{10}(.)+$ I have that regex which will match any string that contains a word
I need some help on Regex. I need to find a word that is
Ok I need a one line php-ready regex that encompasses a number of keywords,
I need to define a (Java) regex that will match any string that does

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.