Reputation: 3510
Below is the sample words that I will use at time of file import
So here are the business rules:
, but it's invalid if there's only space (l.e East Chesterton) ( someword )
( someword )
is optional ( 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 '( )'
\((.*?)\)
Upvotes: 0
Views: 117
Reputation: 1090
I've taken a look at the answer posted here.
^[a-zA-Z\s]{3,}(\([a-zA-Z\s]{3,}\))?$
This would clash with
Only empty spaces would already match.
Besides that the description 'characters' might be a bit vague. I have therefore assumed word characters \w
are what you mean. (in C sharp \w
should include unicode characters like ü
as well. Think of Münster (Germany)
as example.
The new regex would look like this:
^\s*(?:\w{3,}\s*)+(?:\(\s*(?:\w{3,}\s*)+\))?\s*$
Examples here: https://regex101.com/r/gS7kG8/3
Note that the regex101 page works with php,python and js regex, it will not give exact results in case of C# (\w
in php apparently doesn't match unicode for instance)
Upvotes: 0
Reputation: 6547
I think you are almost there. I did a try. Does this comply to all your requirements?
^[a-zA-Z\s]{3,}(\([a-zA-Z\s]{3,}\))?$
https://regex101.com/r/yE9lB0/2
I made the second part optional by putting it in between parenthesis and adding a question mark at the end: (myoptionalexpression)?
Upvotes: 2