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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:11:41+00:00 2026-05-23T14:11:41+00:00

A little while back I answered this question on SO, but I still haven’t

  • 0

A little while back I answered this question on SO, but I still haven’t figured out why my answer worked.

For some reason, a negative lookahead for the start of a string behaves the same as a negative lookbehind.

For example, in PHP

preg_replace("/(?!^)12/", "ab", "12345");   // 12345
preg_replace("/(?<!^)12/", "ab", "12345");  // 12345
preg_replace("/(?!1)23/", "ab", "12345");   // 1ab45
preg_replace("/(?<!1)23/", "ab", "12345");  // 12345

I know it’s not the most useful question ever asked, but this has been nagging me for a couple of weeks.

  • 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-23T14:11:42+00:00Added an answer on May 23, 2026 at 2:11 pm

    The caret is a zero-width assertion. In fact lookaheads and lookbehinds are zero-width as well. Therefore, in this case it doesn’t matter if you’re looking ahead or behind, you’re still looking at the same character position.

    This is explained pretty well in this article.

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

Sidebar

Related Questions

I little while back I posted this question . I have updated that question
This question is related to this question I asked a little while back. The
I had this weird problem a little while ago and haven't been able to
Ok, so a little while back I had some help writing some PHP voting
A while back I posted this question about monitoring a Tomcat server. Since that
I've been attempting to figure this out for a little while now, and it's
Ok A while back I found this wonderful little addon style script for jQuery
OK, I have been researching this problem for a little while and I haven't
I've been trying to figure this out for a little while and I'm sure
I have been working with Rails for a little while now. I got some

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.