i'm trying to sort some text using regex pattern, and i already have something like this:
Pattern pattern = Pattern.compile("\\w{4,30}\\b");
If i'm right it should give me strings of 4 to 30 characters long, but i don't want any number in my Strings too, don't know how to make two filters at the same time, any suggestions?
You may use
"\\b(?!\\d+\\b)\\w{4,30}\\b"
See the regex demo . The main things here are word boundaries ( \\b
) and the negative lookahead construct that restricts the chars the word to be matched should consist of.
Details
\\b
- a word boundary (?!\\d+\\b)
- no 1 or more digits immediately to the right of the current location is allowed up to the end of the word \\w{4,30}
- 3 to 30 word (letter, digit or _
) chars \\b
- a word boundary.
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.