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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:44:03+00:00 2026-05-22T21:44:03+00:00

Hi I have a problem with my regex pattern: preg_match_all(‘/!!\d{3}/’, ‘!!333!!333 !!333 test’, $result);

  • 0

Hi I have a problem with my regex pattern:

preg_match_all('/!!\d{3}/', '!!333!!333 !!333 test', $result);

I want this to match !!333 but not !!333!333. How can I modify this regex to match only a max length of 5 characters – two ! and three numbers.

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

    I find the easiest and most descriptive way to do this is with negative lookaheads and lookbehinds.

    See:

    preg_match_all('/(?<![^\s])!!\d{3}(?![^\s])/', '!!333 !!333!!333 !!333 test !!333', result);
    

    This says: match anything of the form !![0-9][0-9][0-9] which doesn’t have anything other than a space in front or behind it. Note that these lookaheads/lookbehinds aren’t matched themselves, they are “zero-width assertions”, they are thrown away and so you only get “!!333″ etc in your match, not ” !!333″ etc.

    It returns

    [0] => Array
            (
                [0] => !!333
                [1] => !!333
                [2] => !!333
            )
    
    )
    

    Also

    preg_match_all(
        '/(?<![^\s])!!\d{3}(?![^\s])/', 
        '!!333 !!555 !!333 !!123 !!555 !!456 !!333 !!333 !!444 !!444 !!123 !!123 !!123!!123',
        $result));
    

    returns

    [0] => Array
        (
            [0] => !!333
            [1] => !!555
            [2] => !!333
            [3] => !!123
            [4] => !!555
            [5] => !!456
            [6] => !!333
            [7] => !!333
            [8] => !!444
            [9] => !!444
            [10] => !!123
            [11] => !!123
        )
    

    That is, all but the last two which are too long.

    See Lookahead tutorial.

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

Sidebar

Related Questions

I have this regex pattern <(\d+)>(\d+\.\d+|\d{4}\-\d+\-\d+\s+\d{2}:\d{2}:\d{2})(?:\..*?)*\s+(ALER|NOTI) and this is my input (will not matched
I have a problem with regex, using preg_match_all(), to match something of a variable
While doing some small regex task I came upon this problem. I have a
I've tried to accomplish this with regex but it seems not to be working
I have a little problem on RegEx pattern in c#. Here's the rule below:
Possible Duplicate: Java - Regex problem I have list of URLs of types: http://www.example.com/pk/etc
I have problem with return statment >.< I want to store all magazine names
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have a problem with one regex expression to be used so i.e. the
I have a regex problem which bugs me and have no clue how to

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.