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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:41:42+00:00 2026-05-25T10:41:42+00:00

the following is a simplification of a regex i am using. on my development

  • 0

the following is a simplification of a regex i am using. on my development machine both $pattern1 and $pattern2 return a match, however on my production machine only $pattern1 returns a match! clearly the only difference between $pattern1 and $pattern2 is that one of them has brackets around a word. however both are valid patterns which should match the given haystack (as far as i know).

$pattern1 = '/\<a name="ERROR TEXT"\>\<\/a\>\s*?validated\s*?\<\/span\>\s*?\<\/h1\>/';
$pattern2 = '/\<a name="ERROR TEXT"\>\<\/a\>\s*?(validated)\s*?\<\/span\>\s*?\<\/h1\>/';
$haystack = '- IFCS msg value, BOOKMARKED AS ERROR TEXT -->
          <a name="ERROR TEXT"></a>
             validated</span>
       </h1>

                <!-- START: .formActionHolder -->
                <div class="formActionHolder">';
preg_match($pattern1, $haystack, $matches);
print_r($matches);

has anyone found this problem before? note that this is not the whole of the regex – this is a simplified version which i have identified as being the problem. in my actual code, the value of ‘validated’ is not a constant – hence my reason for using brackets to capture the word. of course the patterns have other characters within the parenthesis as well so that i can capture the variable words here. this is just a simplified example which hones in on the problem that i am having with two seemingly fine regexes.

on my development machine i am using php5.3.2 with the pcre 7.8 library and on my production machine i am using php5.2.4 with pcre 7.4.

  • 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-25T10:41:43+00:00Added an answer on May 25, 2026 at 10:41 am

    i had a thought about the ?( combination in $pattern2 so i removed the ? to make

    $pattern = '/\<a name="ERROR TEXT"\>\<\/a\>\s*(validated)\s*?\<\/span\>\s*?\<\/h1\>/';
    

    and that works!! its very strange – possibly even a bug?

    so it looks like the ?(validated) bit was being interpreted as a conditional subpattern rather than the question mark being used to make the \s* ungreedy

    that doesn’t look like correct behavior to me.

    ah well…its a bit of a pain since now my * will be greedy. the regex pattern does what i want in this instance though…

    thanks for all your helpful comments!

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

Sidebar

Related Questions

I'm using a linq query which looks (after some simplification) something like the following:
I have the following XML (simplification): <?xml version=1.0 encoding=utf-8?> <TestCases> <TestCase> <Name>Test1</Name> <Result>Failed</Result> <Properties>
The following code is a simplification of a code in a real application. The
I need to run the following query (this is a simplification of my process):
I'm using asynchronous pipes for inter-process communication (I removed error checks for simplification) int
I have the following: return render_to_response('a.html', {'b': 3}, context_instance=...) in a.html : {{ b
Following http://maksim.sorokin.dk/it/2010/06/10/izpack-with-maven/ I wrote a Maven POM which creates an IzPack installer, using the
I have the following sql (a simplification of the real problem): SELECT * FROM
This is a simplification, but I have an app that has the following methods:
I'm using the following code to discard unsupported physical interfaces / subinterfaces from routers

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.