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 (le 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 '( )'
\((.*?)\)
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)?
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.