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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:09:15+00:00 2026-06-18T00:09:15+00:00

Update : Actually php does not support lookbehind with variable lengths. This approach is

  • 0

Update : Actually php does not support lookbehind with variable lengths. This approach is not possible in php. Any variable length lookbehind will give an error “Compilation failed: lookbehind assertion is not fixed length”

I have the following regex (i’m using php) :

/\d{2}\s\b(ans|year|years|sana|años|anos|sna)\b/i

that matches patterns like :

22 years
49 ans
98 anos

I need to cause it to not match if the input is preceeded by certain words (“since”, “depuis”, etc)

so :

I'm 22 years
I have 49 years

would match, while :

Since 19 years
Depuis 10 ans

would not match.

I’ve tried this, to no effect :

/(?<!(depuis|since|monz))\d{2}\s\b(ans|year|years|sana|años|anos|sna)\b/i

Thanks in advance.

  • 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-18T00:09:16+00:00Added an answer on June 18, 2026 at 12:09 am

    Your lookbehind is not well formed. The “or” conditon in lookbehinds (when used inside parens in PHP) requires same length. Otherwise you can just write the whole lookbehind conditions one by one like in

    $str = "I'm 22 years and I have 49 years but Since 19 years and Depuis 10 ans";
    preg_match_all(
    '~
        (?<!
            \bdepuis\s  |
            \bsince\s   |
            \bmonz\s
        )
        \d{2}\s
        (?:
            ans?    |
            years?  |
            sana    |
            años?   |
            anos?   |
            sna
        )\b
    ~xi',$str,$m);
    print_r($m);
    

    [EDIT 2]

    There’s a chance that there might be multiple empty spaces between the last word and the desired part (like @nhahtdh wrote below in the comments). Although this is not a single pattern here’s how you can avoid such situations.

    $pat =
    '~
        (
            (?(?<=^)(?=\s*)             # if it is the beginning of the string
                (?:\s*)                 # match possible spaces
                |                       # otherwise match
                (?:
                    (?<=\s)             # following a space,
                    (?:                 # a word that is not listed below
                        (?!(?:
                            depuis  |
                            since   |
                            monz
                        ))
                        \S
                    )+
                    \s+                 # and 1 or more spaces
                )
            )
        )
        \d{2}\s+                        # then your pattern itself
        (?:
            ans?    |
            years?  |
            sana    |
            años?   |
            anos?   |
            sna
        )\b
    ~xi';
    preg_match_all($pat,$str,$matches);
    foreach ($matches[0] as $k => &$v)
        // replace the previous word if any
        $v = substr($v,strlen($matches[1][$k]));
    // and delete the reference
    unset($v);
    print_r($matches);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any recommendations how to implement this? table1 will constantly be INSERT
I'm not seeing why my update statement isn't actually updating. Here is what I
I faced this strange situation where foreach like construct of javascript does not work
I am trying to get this jGrowl working but I am not having any
Hello i actually develop a Ios application This application use a PHP webservice to
Update: I reported this as a bug to Apple and they fixed it! All
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
Update : This is no longer an issue from C# 6, which has introduced
Given this XML: <?php $xml = <<<XML <?xml version=1.0 encoding=UTF-8 ?> <root> <project type=residential>
I'm new to Javascript. The code for a jQuery-ajax-php-cooperation does strange things. It works

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.