java - Use Regex to accept a string as long as it contains alphabet -
i want accept string long contains alphabetical letters, example: string teststr = "hello world 1. ?"
i using this: teststr.matches("^[a-za-z\\s]+")
, won't accept strings have characters outside of alphabet.
so wondering how use regex in situation.
could use lookahead check if string contains @ least 1 [a-z]
(?i)^(?=.*[a-z]).*
or without i-caseless modifier: ^(?=.*[a-za-z]).*
/ check only: ^(?=.*[a-za-z])
Comments
Post a Comment