Reputation: 137
I need Regex to filter string to fit with the following conditions :
Example Valid Text :
Developers trust #StackOverflow to help solve #coding problems and use Stack Overflow Careers to find job opportunities. Please visit https://stackoverflow.com/
Example Invalid Text :
Developers trust #StackOverflow to help solve #coding problems and use Stack Overflow Careers to find job opportunities. Please visit https://stackoverflow.com/ or https://stackoverflow.com/company/about
Invalid string above because there are containing two URL.
Any help would be appreciated and thank you very much :)
Upvotes: 1
Views: 1180
Reputation: 1043
I think this will help you
^(?!^([^#]*#[^#]*){5,}$)(?!(.*http(s{0,1}):\/\/){2,})(?=.*[a-z]).{0,300}$
(?!^([^#]*#[^#]*){5,}$)
this will ensure that string should not contain more then 4 #(?!(.*http(s{0,1}):\/\/){2,})
this will ensure that string should not contain more then 2 url(?=.*[a-z])
this will ensure that string should contain at least 1 lower case letter.{0,300}
this will ensure that string should contain not more then 300 charterUpvotes: 3