Below is the sample words that I will use at time of file import
- East Chesterton (Cambridge)
- New york (USA)
- child (parent)
So here are the business rules:
- First word should be at least 3 chars long (l.e child)
- Allow space
, but it's invalid if there's only space (l.e East Chesterton) - The other part of the word is in
( someword ) - The
( someword )is optional - If
( someword )is there it's minimum length is of 3, and spaces are also allowed.
I have achieved this at some level using following expression:
^[a-zA-Z ]{1,}\([a-zA-Z ]{1,}\)$
Now i want to make sure this is correct expression. Is there any way to check with automation to check multiple combination to verify my expression?
How i can achieve optional part (point no. 4), It min whether i pass (somedata) or not that check for first part.
Also to extract data in '( )'
\((.*?)\)
{1,}matches a single occurrence or more, but you said you need at least 3 characters, so that should be{3,}. For optional parts, use?. Note that(...)indicates a group. To match parentheses, you need to escape them:\(and\). Also note that you can use character classes such as\w(word characters) and\s(whitespace characters) instead of explicit ranges. You can also allow (optional) whitespace in-between the first and the second part with\s*(0 or more whitespace characters).^(?=[a-z]{3,})[a-z ]+(?:\p{Zs}\((?=[a-z]{3,})[a-z ]+\))?\r?$(?=[a-z]{3,})does that, but it is also followed up with[a-z ]+, effectively making it a minimum of 4. The second should use*instead of+.