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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:07:14+00:00 2026-05-14T21:07:14+00:00

New question As suggested by Asaph in previous question: Regex to check if exact

  • 0

New question As suggested by Asaph in previous question: Regex to check if exact string exists

I am looking for a way to check if an exact string match exists in another string using Regex or any better method suggested. I understand that you tell regex to match a space or any other non-word character at the beginning or end of a string. However, I don’t know exactly how to set it up.

Search String: #t

Should Match:
String 1: Hello World, Nice to see you! #t
String 2: #T Hello World, Nice to see you!
String 3: Hello World, #t Nice to see you!

Should not Match:
String 1: Hello World, Nice to see you!
String 2: Hello World, Nice to see you! #ta
String 3: #tHello World, Nice to see you!

Edit 2: Added more string samples

Edit 1 for Serg555 and SilentGhost:
Characters allowed in search string:
#[_a-zA-Z0-9]
# is optional.

Requirements:
Search String may be at any character position in the Subject.
There may or may not be a white-space character before or after it.
I do not want it to match if it is part of another string; such as part of a word.

For the sake of this question: I think I would do this using this pattern: /\b\#t\b/gi
However, this is not returning the results as I would have expected.

I am able to find the exact matches for normal strings (strings where # isn’t present) using:

/\b{$search_string}\b/gi

Additional info: this will be used in PHP 5

  • 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-14T21:07:14+00:00Added an answer on May 14, 2026 at 9:07 pm

    All you need is:

    /(?:^|\s)#t\b/i           #t is in the beginning or preceded by space.
    

    \b matches word border, which is a border between word-characters and non-word characters. # is a non-word character, therefore your regex matches only strings like this: abc#t, or ab_#t.

    Also, normally # is not a special character in regex, you don’t need to escape it.

    ETA: Your requirements are rather ambiguous: There may or may not be a white-space character before or after it. I do not want it to match if it is part of another string; such as part of a word.

    1. no white space character before or after? so there will be a non white-space character?
    2. but how is it separated then from other strings? what characters are allowed?

    I think you need to give a comprehensive sample of your possible input strings. Because, as it is my regex works just fine.

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

Sidebar

Related Questions

New Question I am looking for a way in Javascript to get the parent
As suggested in answers to a previous question , I tried using Erlang proplist
In this question about creating a new perl module , it was suggested to
In another question, a user suggested to write code like to that: def list
Pretty new here. But before I ask my question, I'm not looking for teh
As suggested I'm asking new question in new topic. I have a problem with
In another question I posted recently I was suggested to use a java.util.Timer in
This is a followup on my previous question , I am using the 2to3
Making a new question, as was suggested to me. I'm trying to send data
In answering another question , I suggested to use timeit to test the difference

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.