Reputation: 71
My Regex matches words and only allow one space in between. Below is my Regex
^([a-zA-Z\u4e00-\u9fa5]+ )*[a-zA-Z\u4e00-\u9fa5]+$
This works fine but i want to limit the matches including space, how can i do this? For Example:
{2,30}
And this does not work
^(([a-zA-Z\u4e00-\u9fa5]+ )*[a-zA-Z\u4e00-\u9fa5]+$){2,30}
Upvotes: 0
Views: 59
Reputation: 521249
You could use a positive lookahead assertion to check the length:
^(?=.{2,30}$)([a-zA-Z\u4e00-\u9fa5]+ )*[a-zA-Z\u4e00-\u9fa5]+$
^^^^^^^^^^
Explore the regex in the demo below. I removed the unicode characters to make things simpler.
Upvotes: 1