Reputation: 51
Need Regex
^(?:\d{1,3}\h+)?\D\S*(?:\h+\S+){0,3}$ https://regex101.com/r/t2HCLm/1 It is working fine for me. now I want to modify it
How to prevent it from accepting one letter with one space each side of it (one letter word)? I meant that each word's letter limit should more than 1 letter. example: This is a School=false This is the School=true
This is a School=false
This is the School=true
Upvotes: 2
Views: 52
Reputation: 626747
You can use
^(?:\d{1,3}\h+)?[^\d\s]\S+(?:\h+\S{2,}){0,3}$
See the regex demo
Details:
^
- string start(?:\d{1,3}\h+)?
- an optional sequence of one, two or three digits followed with one or more horizontal whitespaces[^\d\s]
- a char other than a digit and whitespace\S+
- one or more non-whitespaces(?:\h+\S{2,}){0,3}
- zero to three sequences of one or more horizontal whitespaces and then two or more non-whitespace chars$
- string end.Upvotes: 1