(?=) didn'work , i just change its position The 2019 Stack Overflow Developer Survey Results Are InHow to change an element's class with JavaScript?How to validate an email address using a regular expression?How do you access the matched groups in a JavaScript regular expression?jQuery Set Cursor Position in Text Areaevent.preventDefault() vs. return falseHow to match “anything up until this sequence of characters” in a regular expression?What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?Regular expression search replace in Sublime Text 2Is Safari on iOS 6 caching $.ajax results?Python string.replace regular expression

Why is Grand Jury testimony secret?

"What time...?" or "At what time...?" - what is more grammatically correct?

What is this 4-propeller plane?

It's possible to achieve negative score?

What does "sndry explns" mean in one of the Hitchhiker's guide books?

What tool would a Roman-age civilization have to grind silver and other metals into dust?

Could JWST stay at L2 "forever"?

"To split hairs" vs "To be pedantic"

A poker game description that does not feel gimmicky

In microwave frequencies, do you use a circulator when you need a (near) perfect diode?

Output the Arecibo Message

Why do UK politicians seemingly ignore opinion polls on Brexit?

Should I write numbers in words or as numerals when there are multiple next to each other?

Is it possible for the two major parties in the UK to form a coalition with each other instead of a much smaller party?

Can distinct morphisms between curves induce the same morphism on singular cohomology?

Is three citations per paragraph excessive for undergraduate research paper?

How was Skylab's orbit inclination chosen?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

If the Wish spell is used to duplicate the effect of Simulacrum, are existing duplicates destroyed?

Monty Hall variation

Pristine Bit Checking

How to deal with fear of taking dependencies

Should I use my personal or workplace e-mail when registering to external websites for work purpose?

Inversion Puzzle



(?=) didn'work , i just change its position



The 2019 Stack Overflow Developer Survey Results Are InHow to change an element's class with JavaScript?How to validate an email address using a regular expression?How do you access the matched groups in a JavaScript regular expression?jQuery Set Cursor Position in Text Areaevent.preventDefault() vs. return falseHow to match “anything up until this sequence of characters” in a regular expression?What is the explanation for these bizarre JavaScript behaviours mentioned in the 'Wat' talk for CodeMash 2012?Regular expression search replace in Sublime Text 2Is Safari on iOS 6 caching $.ajax results?Python string.replace regular expression



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















My regular expression did not execute correctly.



I get different results when I change its position.



"bbbWindows" is not what I wanted. Why not 'bbb2222'?



'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb


'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows









share|improve this question






















  • ?= is a positive lookahead, and it captures nothing.

    – Xhua
    Mar 22 at 3:04

















0















My regular expression did not execute correctly.



I get different results when I change its position.



"bbbWindows" is not what I wanted. Why not 'bbb2222'?



'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb


'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows









share|improve this question






















  • ?= is a positive lookahead, and it captures nothing.

    – Xhua
    Mar 22 at 3:04













0












0








0








My regular expression did not execute correctly.



I get different results when I change its position.



"bbbWindows" is not what I wanted. Why not 'bbb2222'?



'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb


'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows









share|improve this question














My regular expression did not execute correctly.



I get different results when I change its position.



"bbbWindows" is not what I wanted. Why not 'bbb2222'?



'Windowsbbb'.replace(/Windows(?=bbb)/, '2222') // 2222bbb


'bbbWindows'.replace(/(?=bbb)Windows/, '2222') // bbbWindows






javascript regex






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 22 at 2:53









Xu YoungXu Young

184




184












  • ?= is a positive lookahead, and it captures nothing.

    – Xhua
    Mar 22 at 3:04

















  • ?= is a positive lookahead, and it captures nothing.

    – Xhua
    Mar 22 at 3:04
















?= is a positive lookahead, and it captures nothing.

– Xhua
Mar 22 at 3:04





?= is a positive lookahead, and it captures nothing.

– Xhua
Mar 22 at 3:04












2 Answers
2






active

oldest

votes


















1














Lookaheads ((?=...)) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,



/Windows(?=bbb)/


Will match the substring Windows only if the substring immediately following the s also matches the pattern bbb. On the other hand,



/(?=bbb)Windows/


Will match the substring Windows only if the substring immediately following start position of the initial match also matches the pattern bbb—which is impossible, no string will ever match that.



The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)) and tweak your replacement string to insert this matched substring in the appropriate place ($N). For example:






console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222








share|improve this answer
































    0














    You should use positive lookbehind when the asserted pattern is behind the matching pattern:



    'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')





    share|improve this answer























    • Lookbehinds are not supported in JavaScript.

      – p.s.w.g
      Mar 22 at 3:17











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292231%2fdidnwork-i-just-change-its-position%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Lookaheads ((?=...)) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,



    /Windows(?=bbb)/


    Will match the substring Windows only if the substring immediately following the s also matches the pattern bbb. On the other hand,



    /(?=bbb)Windows/


    Will match the substring Windows only if the substring immediately following start position of the initial match also matches the pattern bbb—which is impossible, no string will ever match that.



    The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)) and tweak your replacement string to insert this matched substring in the appropriate place ($N). For example:






    console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
    console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222








    share|improve this answer





























      1














      Lookaheads ((?=...)) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,



      /Windows(?=bbb)/


      Will match the substring Windows only if the substring immediately following the s also matches the pattern bbb. On the other hand,



      /(?=bbb)Windows/


      Will match the substring Windows only if the substring immediately following start position of the initial match also matches the pattern bbb—which is impossible, no string will ever match that.



      The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)) and tweak your replacement string to insert this matched substring in the appropriate place ($N). For example:






      console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
      console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222








      share|improve this answer



























        1












        1








        1







        Lookaheads ((?=...)) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,



        /Windows(?=bbb)/


        Will match the substring Windows only if the substring immediately following the s also matches the pattern bbb. On the other hand,



        /(?=bbb)Windows/


        Will match the substring Windows only if the substring immediately following start position of the initial match also matches the pattern bbb—which is impossible, no string will ever match that.



        The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)) and tweak your replacement string to insert this matched substring in the appropriate place ($N). For example:






        console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
        console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222








        share|improve this answer















        Lookaheads ((?=...)) are zero-length assertions. They assert that the substring following that position in the original string must match the given pattern. In other words,



        /Windows(?=bbb)/


        Will match the substring Windows only if the substring immediately following the s also matches the pattern bbb. On the other hand,



        /(?=bbb)Windows/


        Will match the substring Windows only if the substring immediately following start position of the initial match also matches the pattern bbb—which is impossible, no string will ever match that.



        The easiest way to get this pattern to work would be to use a regular 'in-line' group ((...)) and tweak your replacement string to insert this matched substring in the appropriate place ($N). For example:






        console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
        console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222








        console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
        console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222





        console.log('Windowsbbb'.replace(/Windows(bbb)/, '2222$1')) // 2222bbb
        console.log('bbbWindows'.replace(/(bbb)Windows/, '$12222')) // bbb2222






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 22 at 3:38

























        answered Mar 22 at 3:27









        p.s.w.gp.s.w.g

        120k19216257




        120k19216257























            0














            You should use positive lookbehind when the asserted pattern is behind the matching pattern:



            'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')





            share|improve this answer























            • Lookbehinds are not supported in JavaScript.

              – p.s.w.g
              Mar 22 at 3:17















            0














            You should use positive lookbehind when the asserted pattern is behind the matching pattern:



            'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')





            share|improve this answer























            • Lookbehinds are not supported in JavaScript.

              – p.s.w.g
              Mar 22 at 3:17













            0












            0








            0







            You should use positive lookbehind when the asserted pattern is behind the matching pattern:



            'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')





            share|improve this answer













            You should use positive lookbehind when the asserted pattern is behind the matching pattern:



            'bbbWindows'.replace(/(?<=bbb)Windows/, '2222')






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 22 at 2:57









            blhsingblhsing

            43k41743




            43k41743












            • Lookbehinds are not supported in JavaScript.

              – p.s.w.g
              Mar 22 at 3:17

















            • Lookbehinds are not supported in JavaScript.

              – p.s.w.g
              Mar 22 at 3:17
















            Lookbehinds are not supported in JavaScript.

            – p.s.w.g
            Mar 22 at 3:17





            Lookbehinds are not supported in JavaScript.

            – p.s.w.g
            Mar 22 at 3:17

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292231%2fdidnwork-i-just-change-its-position%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript