Javascript match a string which start with a specific char from the set of chars and end with same char using Regular ExpressionWhat is the best regular expression to check if a string is a valid URL?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular expression to stop at first matchHow to match “anything up until this sequence of characters” in a regular expression?javascript to match string start with “ and end with ”; and anything in between?JavaScript Regex finding all substrings matching the starting and ending patternmatching words starting and ending with same letterregex matching for string with character limit, specific start characters, and terminationMatch the same start and end character of a string with Regex

Why do the non-leaf Nodes of Merkle tree need to be hashed?

Why was wildfire not used during the Battle of Winterfell?

Would encrypting a database protect against a compromised admin account?

Why do unstable nuclei form?

Has there been evidence of any other gods?

Thesis' "Future Work" section – is it acceptable to omit personal involvement in a mentioned project?

Watching the game, having a puzzle

How to efficiently lower your karma

Has magnetic core memory been used beyond the Moon?

What do "KAL." and "A.S." stand for in this inscription?

Was there a contingency plan in place if Little Boy failed to detonate?

Is this state of Earth possible, after humans left for a million years?

Pre-1993 comic in which Wolverine's claws were turned to rubber?

Why does it take longer to fly from London to Xi'an than to Beijing

Is it a good idea to copy a trader when investing?

Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks?

Getting a error after using setState with a promise

Can a surprised creature fall prone voluntarily on their turn?

Translation of the latin word 'sit' in Thomas Aquinas' works

What's the difference between const array and static const array in C/C++

How can I avoid subordinates and coworkers leaving work until the last minute, then having no time for revisions?

How to make a language evolve quickly?

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech

Peculiarities in low dimensions or low order or etc



Javascript match a string which start with a specific char from the set of chars and end with same char using Regular Expression


What is the best regular expression to check if a string is a valid URL?Regular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?Regular expression to stop at first matchHow to match “anything up until this sequence of characters” in a regular expression?javascript to match string start with “ and end with ”; and anything in between?JavaScript Regex finding all substrings matching the starting and ending patternmatching words starting and ending with same letterregex matching for string with character limit, specific start characters, and terminationMatch the same start and end character of a string with Regex






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








2















I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.



so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:



function regexVar() 

var re = /(.).*1/
return re;


console.log("obcdo".test(s));


let suppose the specific set of chars is the vowel




(a, e, i, o, u)




in this case:




abcd ----> false



obcdo ----> true



ixyz ----> false











share|improve this question






























    2















    I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.



    so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:



    function regexVar() 

    var re = /(.).*1/
    return re;


    console.log("obcdo".test(s));


    let suppose the specific set of chars is the vowel




    (a, e, i, o, u)




    in this case:




    abcd ----> false



    obcdo ----> true



    ixyz ----> false











    share|improve this question


























      2












      2








      2








      I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.



      so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:



      function regexVar() 

      var re = /(.).*1/
      return re;


      console.log("obcdo".test(s));


      let suppose the specific set of chars is the vowel




      (a, e, i, o, u)




      in this case:




      abcd ----> false



      obcdo ----> true



      ixyz ----> false











      share|improve this question
















      I need to achieve a particular task in javascript, in which my goal is to match the string which starts with a char from a specific set of characters like vowel and ends with the same character where the length of the string is greater than three.



      so far I have done the following code that starts and ends with the same character but doesn't know how to specify it that the first char is from the specific set of character:



      function regexVar() 

      var re = /(.).*1/
      return re;


      console.log("obcdo".test(s));


      let suppose the specific set of chars is the vowel




      (a, e, i, o, u)




      in this case:




      abcd ----> false



      obcdo ----> true



      ixyz ----> false








      javascript regex






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 10:09







      Ali Azim

















      asked Mar 23 at 9:52









      Ali AzimAli Azim

      13313




      13313






















          2 Answers
          2






          active

          oldest

          votes


















          3














          You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^ and $ to anchor the pattern to the start and end of the string, and repeat with 2, rather than * to make sure the whole string is at least 4 characters long:



          /^([aeiou]).+1$/





          const re = /^([aeiou]).2,1$/
          console.log(
          re.test('abcd'),
          re.test('obcdo'),
          re.test('ixyz')
          );








          share|improve this answer
































            0














            You can use this pattern



            /^([aeiou]).+1$/i



            • ^ - Start of string


            • ([aeiou]) - Matches a,e,i,o,u any one of that. (group 1)


            • .+ - Match anything except new line.


            • 1 - Match group 1


            • $ - End of string




            let startAndEnd = (str) =>
            return /^([aeiou]).+1$/i.test(str)


            console.log(startAndEnd(`ixyz`))
            console.log(startAndEnd(`abcd`))
            console.log(startAndEnd(`obcdo`))








            share|improve this answer


















            • 1





              can you please explain what i is used for in this RegExp?

              – Ali Azim
              Mar 23 at 10:04






            • 1





              @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

              – Code Maniac
              Mar 23 at 10:05












            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%2f55312510%2fjavascript-match-a-string-which-start-with-a-specific-char-from-the-set-of-chars%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









            3














            You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^ and $ to anchor the pattern to the start and end of the string, and repeat with 2, rather than * to make sure the whole string is at least 4 characters long:



            /^([aeiou]).+1$/





            const re = /^([aeiou]).2,1$/
            console.log(
            re.test('abcd'),
            re.test('obcdo'),
            re.test('ixyz')
            );








            share|improve this answer





























              3














              You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^ and $ to anchor the pattern to the start and end of the string, and repeat with 2, rather than * to make sure the whole string is at least 4 characters long:



              /^([aeiou]).+1$/





              const re = /^([aeiou]).2,1$/
              console.log(
              re.test('abcd'),
              re.test('obcdo'),
              re.test('ixyz')
              );








              share|improve this answer



























                3












                3








                3







                You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^ and $ to anchor the pattern to the start and end of the string, and repeat with 2, rather than * to make sure the whole string is at least 4 characters long:



                /^([aeiou]).+1$/





                const re = /^([aeiou]).2,1$/
                console.log(
                re.test('abcd'),
                re.test('obcdo'),
                re.test('ixyz')
                );








                share|improve this answer















                You need to use a character set to ensure the captured character is one of the ones you want, backreference the first captured group at the end of the pattern, not the third group (your pattern doesn't have 3 capture groups), use ^ and $ to anchor the pattern to the start and end of the string, and repeat with 2, rather than * to make sure the whole string is at least 4 characters long:



                /^([aeiou]).+1$/





                const re = /^([aeiou]).2,1$/
                console.log(
                re.test('abcd'),
                re.test('obcdo'),
                re.test('ixyz')
                );








                const re = /^([aeiou]).2,1$/
                console.log(
                re.test('abcd'),
                re.test('obcdo'),
                re.test('ixyz')
                );





                const re = /^([aeiou]).2,1$/
                console.log(
                re.test('abcd'),
                re.test('obcdo'),
                re.test('ixyz')
                );






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 23 at 10:01

























                answered Mar 23 at 9:55









                CertainPerformanceCertainPerformance

                105k166797




                105k166797























                    0














                    You can use this pattern



                    /^([aeiou]).+1$/i



                    • ^ - Start of string


                    • ([aeiou]) - Matches a,e,i,o,u any one of that. (group 1)


                    • .+ - Match anything except new line.


                    • 1 - Match group 1


                    • $ - End of string




                    let startAndEnd = (str) =>
                    return /^([aeiou]).+1$/i.test(str)


                    console.log(startAndEnd(`ixyz`))
                    console.log(startAndEnd(`abcd`))
                    console.log(startAndEnd(`obcdo`))








                    share|improve this answer


















                    • 1





                      can you please explain what i is used for in this RegExp?

                      – Ali Azim
                      Mar 23 at 10:04






                    • 1





                      @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

                      – Code Maniac
                      Mar 23 at 10:05
















                    0














                    You can use this pattern



                    /^([aeiou]).+1$/i



                    • ^ - Start of string


                    • ([aeiou]) - Matches a,e,i,o,u any one of that. (group 1)


                    • .+ - Match anything except new line.


                    • 1 - Match group 1


                    • $ - End of string




                    let startAndEnd = (str) =>
                    return /^([aeiou]).+1$/i.test(str)


                    console.log(startAndEnd(`ixyz`))
                    console.log(startAndEnd(`abcd`))
                    console.log(startAndEnd(`obcdo`))








                    share|improve this answer


















                    • 1





                      can you please explain what i is used for in this RegExp?

                      – Ali Azim
                      Mar 23 at 10:04






                    • 1





                      @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

                      – Code Maniac
                      Mar 23 at 10:05














                    0












                    0








                    0







                    You can use this pattern



                    /^([aeiou]).+1$/i



                    • ^ - Start of string


                    • ([aeiou]) - Matches a,e,i,o,u any one of that. (group 1)


                    • .+ - Match anything except new line.


                    • 1 - Match group 1


                    • $ - End of string




                    let startAndEnd = (str) =>
                    return /^([aeiou]).+1$/i.test(str)


                    console.log(startAndEnd(`ixyz`))
                    console.log(startAndEnd(`abcd`))
                    console.log(startAndEnd(`obcdo`))








                    share|improve this answer













                    You can use this pattern



                    /^([aeiou]).+1$/i



                    • ^ - Start of string


                    • ([aeiou]) - Matches a,e,i,o,u any one of that. (group 1)


                    • .+ - Match anything except new line.


                    • 1 - Match group 1


                    • $ - End of string




                    let startAndEnd = (str) =>
                    return /^([aeiou]).+1$/i.test(str)


                    console.log(startAndEnd(`ixyz`))
                    console.log(startAndEnd(`abcd`))
                    console.log(startAndEnd(`obcdo`))








                    let startAndEnd = (str) =>
                    return /^([aeiou]).+1$/i.test(str)


                    console.log(startAndEnd(`ixyz`))
                    console.log(startAndEnd(`abcd`))
                    console.log(startAndEnd(`obcdo`))





                    let startAndEnd = (str) =>
                    return /^([aeiou]).+1$/i.test(str)


                    console.log(startAndEnd(`ixyz`))
                    console.log(startAndEnd(`abcd`))
                    console.log(startAndEnd(`obcdo`))






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 23 at 9:57









                    Code ManiacCode Maniac

                    13.2k21034




                    13.2k21034







                    • 1





                      can you please explain what i is used for in this RegExp?

                      – Ali Azim
                      Mar 23 at 10:04






                    • 1





                      @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

                      – Code Maniac
                      Mar 23 at 10:05













                    • 1





                      can you please explain what i is used for in this RegExp?

                      – Ali Azim
                      Mar 23 at 10:04






                    • 1





                      @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

                      – Code Maniac
                      Mar 23 at 10:05








                    1




                    1





                    can you please explain what i is used for in this RegExp?

                    – Ali Azim
                    Mar 23 at 10:04





                    can you please explain what i is used for in this RegExp?

                    – Ali Azim
                    Mar 23 at 10:04




                    1




                    1





                    @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

                    – Code Maniac
                    Mar 23 at 10:05






                    @AliAzim i flag is used for case insensitivity. so if you use i flag, regex will treat uppercase and lowercase letters as same character. else it will treat them as two different characters

                    – Code Maniac
                    Mar 23 at 10:05


















                    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%2f55312510%2fjavascript-match-a-string-which-start-with-a-specific-char-from-the-set-of-chars%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권, 지리지 충청도 공주목 은진현