Is there a regex which accepts any symbol?
EDIT: To clarify what I'm looking for.. I want to build a regex which will accept ANY number of whitespaces and the it must contain atleast 1 symbol (e.g , . " ' $ £ etc.) or (not exclusive or) at least 1 character.
Matching a Single Character Using Regex By default, the '. ' dot character in a regular expression matches a single character without regard to what character it is. The matched character can be an alphabet, a number or, any special character.
$ means "Match the end of the string" (the position after the last character in the string). Both are called anchors and ensure that the entire string is matched instead of just a substring.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
Special Characters in Java Regular Expressions Regex is a type of textual syntax representing patterns for text matching. Regular expressions make use of special characters such as . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ .
Yes. The dot (.
) will match any symbol, at least if you use it in conjunction with Pattern.DOTALL
flag (otherwise it won't match new-line characters). From the docs:
In dotall mode, the expression . matches any character, including a line terminator. By default this expression does not match line terminators.
Regarding your edit:
I want to build a regex which will accept ANY number of whitespaces and the it must contain atleast 1 symbol (e.g , . " ' $ £ etc.) or (not exclusive or) at least 1 character.
Here is a suggestion:
\s*\S+
\s*
any number of whitespace characters\S+
one or more ("at least one") non-whitespace character.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With