Grouping and Capturing

Matching Word Boundaries

You have a test String S. Your task is to write a regex which will match word starting with vowel (a,e,i,o, u, A, E, I , O or U). The matched word can be of any length. The matched word should consist of letters (lowercase and uppercase both) only. The matched word must start and end with a word boundary.

\b[aeiouAEIOU][a-zA-Z]*\b

Capturing and Non-Capturing Groups

You have a test String S. Your task is to write a regex which will match S with the following condition:

  • S should have 3 or more consecutive repetitions of ok.

(ok){3,}

Alternative Matching

Given a test string, s, write a RegEx that matches s under the following conditions:

  • must start with Mr., Mrs., Ms., Dr. or Er..

  • The rest of the string must contain only one or more English alphabetic letters (upper and lowercase).

^(Mr\.|Mrs\.|Ms\.|Dr\.|Er\.)[a-zA-Z]+$

Last updated