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

The Archive Base Latest Questions

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

Hello All , I am trying to widen the scope on a preg_match I

  • 0

Hello All,

I am trying to widen the scope on a preg_match I currently use in a shoutbox. I am struggling to build on my current regular expression to obtain the desired identification. Please see the current regex I am using followed by some information on the matches I would like to achieve.


Current regular expression:

~\bf+(?:\.+|\s+)?r+(?:\.+|\s+)?e+(?:\.+|\s+)?d+(?:\.+|)?\b~i

Desired match info:

[01] Lorem ipsum dolor fred sit amet.

  • Identify key word.

[02] Lorem ipsum dolor $fred sit amet.

  • Identify single dollar symbol and key word.

[03] Lorem ipsum dolor $ofred sit amet.

  • Identify single dollar symbol followed by a single alphanumeric character and key word.

[04] Lorem ipsum dolor $ooofred sit amet.

  • Identify single dollar symbol followed by multiple alphanumeric characters and key word.

[05] Lorem ipsum dolor $$$ooofred sit amet.

  • Identify multiple dollar symbols followed by multiple alphanumeric characters and key word.

[06] Lorem ipsum dolor $$$ofred sit amet.

  • Identify multiple dollar symbols followed by a single alphanumeric character and key word.

[07] Lorem ipsum dolor $o$oo$$$ofred sit amet.

  • Identify any combination of dollar symbols and alphanumeric characters followed by key word.

[08] Lorem ipsum dolor $o$oo $$$ofred sit amet.

  • Spaces break the identification

[09] $ofred sit amet.

  • Identified with no leading spaces

[10] Lorem ipsum dolor $ofred

  • Identified with no trailing spaces

[11] Lorem ipsum dolor $ofred!

  • Identified with trailing symbols

Thank you for any help, it’s much appreciated.

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

    This has to be the longest explanation I have ever seen for a regex that is so small:

    if (preg_match('/(?<=^|\s)(?:\bfred\b|\$[$\w]*fred\b)/x', $subject, $regs)) {
        $result = $regs[0];
    }
    

    Explanation:

    "
    (?<=           # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
                   # Match either the regular expression below (attempting the next alternative only if this one fails)
          ^        # Assert position at the beginning of the string
       |           # Or match regular expression number 2 below (the entire group fails if this one fails to match)
          \s       # Match a single character that is a “whitespace character” (spaces, tabs, line breaks, etc.)
    )
    (?:            # Match the regular expression below
                   # Match either the regular expression below (attempting the next alternative only if this one fails)
          \b       # Assert position at a word boundary
          fred     # Match the characters “fred” literally
          \b       # Assert position at a word boundary
       |           # Or match regular expression number 2 below (the entire group fails if this one fails to match)
          \$       # Match the character “$” literally
          [$\w]    # Match a single character present in the list below
                   # The character “$”
                   # A word character (letters, digits, etc.)
             *     # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
          fred     # Match the characters “fred” literally
          \b       # Assert position at a word boundary
    )
    "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello All , I am trying to use preg_match to identify if a single
Currently using Telerik ASP .NET MVC Controls version 2011.2.712 Hello all, I am trying
hello guys I am trying to extract all the anchor links from aol but
Hello every One i am trying to get Ist date of All months in
Hello all i have a button i am trying to let users share a
Hello all and thanks for reading, Im trying to make a simple wave animation
Hello to all you people out there I have been trying to download the
Hello all I am trying to make a new software that it gives me
Hello all I'm just trying to have my border around my table cell right
Hello I am trying to create a query that deletes all data that is

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.