Regex for ONE-or-more letters/digits And ZERO-or-more spaces

java, regex

Solution

I believe you can do something like this:

([ ]*+[0-9A-Za-z]++[ ]*+)+

This is 0 or more spaces, followed by at least 1 alphanum char, followed by 0 or more spaces

^^ that whole thing at least once.

Using Pshemo's idea of possessive quantifiers to speed up the regex.

Problem

I want to allow 0 or more white spaces in my string and one or more A-Z or a-z or 0-9 in my string. Regex allowing a space character in Java suggests `[0-9A-Za-z ]+`. I doubt that, this regex matches patterns having zero or more white spaces. What to do to allow 0 or more whitespaces anywhere in the string and one or more characters anywhere in the string. Will this work? `([0-9A-Za-z]+)([ ]*)`

Original source

Related problems