Match the same start and end character of a string with Regex

后端 未结 4 785
醉话见心
醉话见心 2021-02-05 02:02

I\'m trying to match the start and end character of a string to be the same vowel. My regex is working in most scenarios, but failing in others:

var re = /([aeio         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-05 02:31

    Just a different version of @Hristiyan Dodov answer that I have written for fun.

    regex = /^(a|e|i|o|u).*\1$/
    
    const strings = ['abcde', 'abcda', 'aabcdaa', 'aeqwae', 'ouqweru']
    
    strings.forEach((e)=>{
      const result = regex.test(e)
      console.log(e, result)
    })

提交回复
热议问题