(?=) 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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현