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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:19:35+00:00 2026-05-16T00:19:35+00:00

Why doesn’t this look-behind assertion work when it’s anchored to the front of the

  • 0

Why doesn’t this look-behind assertion work when it’s anchored to the front of the string? Run the following code and you’ll see that the first test passes but the second, which varies only by the ^ anchor, fails.

use Test::More tests => 2;

my $s = '/123/456/hello';    
$s =~ s{(?<=/)\d+(?=/\d+/hello)}{0};  # unanchored
is($s, '/0/456/hello', 'unanchored'); # passes

$s = '/123/456/hello';
$s =~ s{^(?<=/)\d+(?=/\d+/hello)}{0}; # anchored
is($s, '/0/456/hello', 'anchored');   # fails

Moving the ^ into the look-behind assertion isn’t an option for me (this is an extremely simplified example) but that does fix the problem. I’ve found an alternate way to do what I want, but I’m curious why this approach didn’t work. I’ve tested this on perl 5.8.8 and perl 5.10.0.

  • 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-16T00:19:36+00:00Added an answer on May 16, 2026 at 12:19 am

    Remember that the assertion is zero-width and doesn’t consume the characters it matches. So the anchor has to go inside the assertion, otherwise the whole expression doesn’t match.

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

Sidebar

Related Questions

Why doesn't this code work? I'am using FF. <head> <script type=text/javascript> document.getElementById(someID).onclick = function(){
Why doesn't Html.ActionLink work in the below code? This is a page in the
This doesn't seem to work: NSString *string = [[NSString alloc] init]; string = @%@M,
Why doesn't this jQuery code work? $(document).ready(function () { $('currentPage').click(function() { $('myaccount').slideDown('slow', function() {
This doesn't work: string temp; cout << Press Enter to Continue; cin >> temp;
Why doesn't the following code work? $('select option').live('click', function(){ alert('hello') }) html: <select class=ok>
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
Why doesn't this work: <Style TargetType=s:Substance> <Setter Property=Template> <Setter.Value> <DataTemplate> <StackPanel> <TextBlock Text={TemplateBinding Name}/>
This doesn't work: $to = 'myemail@gmail.com'; $from = 'test@test.com'; $subj = 'test'; $message =
There doesn't seem to be a question for this, and it seems strange that

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.