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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:58:29+00:00 2026-06-04T04:58:29+00:00

Possible Duplicate: What do ^ and $ mean in a regular expression? I’m not

  • 0

Possible Duplicate:
What do ^ and $ mean in a regular expression?

I’m not good at all at regular expression, i know they are so much important but never found the time to study them. Anyway i’m just tring to ensure that, among these strings:

MAX_AGE_60
MAX_AGE_80
...
MAX_AGE_X

where more in general X is a integer, at least one match is found and get the number X. So following the example on PHP documentation i wrote this:

// Starts and ends with the literal 'MAX_AGE_' followed by a group that is a 
// number with at least one digit. Case insensitive
$pattern = '/^MAX_AGE_(?P<max>\d+)$/i';

$test    = 'MAX_AGE_80';
$matches = array();

preg_match($pattern, $test, $matches);
var_dump($matches);

The result is wrong (suprise…):

array (size=0)
  empty

Removing start/end delimiters (^ and $) i get the correct result:

array (size=3)
  0     => string 'MAX_AGE_80' (length=10)
  'max' => string '80' (length=2)
  1     => string '80' (length=2)

So why i can’t force that the string must start and end with that pattern? And how should interpret the result array? I mean indexes 0, 1 and max?

  • 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-04T04:58:30+00:00Added an answer on June 4, 2026 at 4:58 am

    I’m not sure what you’re doing between the parentheses there. Try this:

    $pattern = '/^MAX_AGE_[\p{N}]+$/iu';
    

    And the difference between ^$ and not, is that they flag only matches that are at the beginning and/or the end of the LINE

    You can use this site to test your expressions (non unicode):
    http://www.gskinner.com/RegExr/

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

Sidebar

Related Questions

Possible Duplicate: What does 'foo' really mean? I hope it is not the most
Possible Duplicate: What does “WARN Could not determine content-length of response body.” mean and
Possible Duplicate: What does # mean in LISP I am learning lisp, but one
Possible Duplicate: What does the variable $this mean in PHP? I know this is
Possible Duplicate: Regular expression where part of string must be number between 0-100 I'd
Possible Duplicate: Reference - What does this symbol mean in PHP? I googled much
Possible Duplicate: What does “WARN Could not determine content-length of response body.” mean and
Possible Duplicate: What does it mean to have an undefined reference to a static
Possible Duplicate: What does new() mean? Like in title. I wonder what this syntax
Possible Duplicate: What does ||= (or equals) mean in Ruby? It's hard to search

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.