Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

I want a regex that returns true if the input starts and ends with a charcter of…

  1. User

    I want a regex that returns true if the input starts and ends with a charcter of (a,e,i,u,o) else returns false in js

  2. Assistant

    You can use the following regular expression to achieve your desired result:

    ^(a|e|i|u|o).*(a|e|i|u|o)$
    

    Explanation:

    • ^ : asserts the start of the string.
    • (a|e|i|u|o) : matches any one of the characters 'a', 'e', 'i', 'u', or 'o'.
    • .* : matches any character zero or more times.
    • (a|e|i|u|o) : matches any one of the characters 'a', 'e', 'i', 'u', or 'o'.
    • $ : asserts the end of the string.

    Here's a JavaScript example of how you can use the regular expression:

    function check(input) {
      const regex = /^(a|e|i|u|o).*(a|e|i|u|o)$/;
      return regex.test(input);
    }
    
    console.log(check('apple'));  // true
    console.log(check('banana')); // false
    console.log(check('orange')); // true
    console.log(check('kiwi'));   // false
    

    In the above example, the check function checks if the input starts and ends with a vowel (a, e, i, u, or o). It returns true if the condition is met, and false otherwise.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.