简体   繁体   中英

Use Regex to accept a string as long as it contains alphabet

I want to accept a string as long as it contains alphabetical letters, for example: String testStr = "hello world 1. ?"

I am currently using this: testStr.matches("^[a-zA-Z\\\\s]+") , but it won't accept strings that have characters outside of the alphabet.

So I am wondering how to use regex in this situation.

Could use a lookahead to check if the string contains at least one [az]

(?i)^(?=.*[a-z]).*

Or without the i-caseless modifier : ^(?=.*[a-zA-Z]).* / Check only: ^(?=.*[a-zA-Z])

test at regex101

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM