I want a create a regular expression that matches the certain rules.
I found this RE – /^.*\(.*\).*$/g but i also wanted to have validation on second string inside parenthesis.
eg-
United Kingdom (English)
Belgium (Dutch)
ie- expression for [string space string inside parenthesis with at least 3 length of inside string.].
Thank you in advance.
>Solution :
In JavaScript:
const pattern = /^[A-Za-z\s]+\([A-Za-z]{3,}\)$/;
const str1 = 'United Kingdom (English)';
const str2 = 'Belgium (Dutch)';
console.log(pattern.test(str1)); // true
console.log(pattern.test(str2)); // true
Explanation of the pattern:
^ asserts the start of the string.
[A-Za-z\s]+ matches one or more letters or spaces.
\( matches the opening parenthesis.
[A-Za-z]{3,} matches three or more letters (assumed to be the inside string you mentioned).
\) matches the closing parenthesis.
$ asserts the end of the string.