Regular expression only accepts 0 or 5.
Is there a regex expression to evaluate that?
Thanks.
Asked
Active
Viewed 2,302 times
-6

dani77
- 199
- 2
- 5
- 26
-
You need to go actually learn regexes. Asking if a regex can do this is like asking whether Java can add numbers, or asking whether cars can move. – user2357112 Nov 24 '16 at 01:03
-
@user2357112 I don't want to learn regex, I only want to know that. Thanks for subtract me reputation. – dani77 Nov 24 '16 at 01:19
2 Answers
2
You can use either "0|5"
or "[05]"
. The first is an alternative, the second is a character class. They will behave identically. See the documentation for Pattern
for more information on the building blocks for regular expressions.

Ted Hopp
- 232,168
- 48
- 399
- 521
0
Read this. And use this:
"^[05]$"

Yevhen Kuzmovych
- 10,940
- 7
- 28
- 48
-
The question is tagged `java` and you're referring OP to .NET documentation? Cool. – Ted Hopp Nov 24 '16 at 01:08
-
@TedHopp Does Regex Language depends on the language you use it in? – Yevhen Kuzmovych Nov 24 '16 at 01:13
-
@YevhenKuzmovych not for such a simple regex, but there are huge diffrences between implementations. – Sebastian Proske Nov 24 '16 at 01:16
-
The basics are pretty much identical, but there are differences. See, e.g., [this thread](http://stackoverflow.com/questions/12401794/differences-in-regex-between-java-net-and-javascript) and especially some of the resources linked to from there. – Ted Hopp Nov 24 '16 at 01:18
-