0

I need to check given text is validate as a wep key. So I need to check all below regular expressions for one field. Is there a way to do that with regula?

^(([0-9A-Fa-f]{10})|)$

^(([\\s\\S]{5})|)$

^(([0-9A-Fa-f]{26})|)$

^(([\\s\\S]{13})|)$

^(([0-9A-Za-z]{58})|)$

^(([0-9A-Fa-f]{24})|)$

[\\s\\S]
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
Necip Onur Uzun
  • 1,115
  • 3
  • 13
  • 16
  • I'm pretty sure that you don't really want to check those regexes. Most of them don't make much sense, or they overlap a lot. And who is using WEP these days, anyway? – Tim Pietzcker Nov 14 '11 at 13:43

2 Answers2

0

If you want to check whether a string is a) composed entirely of hexadecimal digits and b) exactly 0, 10, 24, 26 or 58 characters in length (although I don't get what you want with 24 digits), then you can either use

^[0-9a-fA-F]*$

and assert that the length of the match is exactly 0, 10, 24, 26 or 58. Or you can do it in a single regex:

^(?:[0-9a-fA-F]{10}|[0-9a-fA-F]{24}|[0-9a-fA-F]{26}|[0-9a-fA-F]{58})?$
Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561
0

In addition to @Tim's answer :

^(([0-9A-Fa-f]{10})|)$

You realize that this matches also nothing right? And you have this in each and every regex? Why?

Then you have [\\s\\S] which matches everything. It is unclear to me and possibly all others what you are trying to achieve here. Please edit your question.

FailedDev
  • 26,680
  • 9
  • 53
  • 73
  • Hi, sorry I'am new at regex. Can you explain why `^(([0-9A-Fa-f]{10})|)$` matches nothing? – Necip Onur Uzun Nov 14 '11 at 14:36
  • Because the expression `^(([0-9A-Fa-f]{10})|)$` says to match at the beginning (`^`), then match _either_ the expression `([0-9A-Fa-f]{10})` **OR** the expression between the "or" symbol (`|`) and the closing parentheses (`)`), which is a zero length string, then finally to match at the end (`$`). It will thus match beginning (`^`), nothing, ending (`$`). – Code Jockey Nov 14 '11 at 17:14