mercredi 9 août 2017

Sequences that can have only one part using regex


for my application in Ember, I need to parse a string from a form, this string must be a hex number, it can only have one bytes, that depend of an other part of my code, but I think that there is a regex for this.
Here, you can see that my current regex:

/([0-9a-fA-F][0-9a-fA-F]:)+[0-9a-fA-F][0-9a-fA-F]/

With this, this is some example,

00:11:22:4a -> match
00:a2 -> match (coded on 2 bytes)
00:a -> no match (missing a nibble)
00:00:00:1q -> no match (out of range(hex number))
00 -> no match (abnormal, its an hex number on one bytes)

So my question here (or my problem, take it as you want), is that I can't have only one part of my sequences.
Can you please give me some tips, that would be really appreciated.
I'm sure this is basic knowledge or something, but I couldn't find any information for my problem. (plus I'm not good with regex)




Aucun commentaire:

Enregistrer un commentaire