The best way is to use so called regular expressions.
Regular expressions are native objects of the language.
They are just patterns against which strings match. It takes whatever finds before it to indicate that it should be matched one or more times. When you want to use a special character as a literal for matching, escape it with the inverted slash. No minimum value is the same as 0, and no maximum value stands for 'any'. As you see, regular expressions are somewhat a black art at first sight, but if you take some time to delve into them, they will reveal themselves as a powerful addition to your developer toolset.