I’m still trying to learn how to format my own expressions… so I’m having problems trying to figure out this one. Can anyone help me with the regular expression for finding this oil weight format: 10W-30 or 0W-30.
Basically, the first number can either be two digits or one, followed by the letter W and a dash… and the last two characters must be a two digit number.
So if x’s were numbers: either xW-xx or xxW-xx.
I’m still looking into it myself… but anyone can help I would really appreciative. Thanks.
This is what I have so far:
/^([0-9]){1,2}[W]-{2,2}$/
Am I missing anything?
This is a really simple regex, checkout the W3 docs on how to implement it.
Quick explanation of whats going on here:
Wisn’t a regex char command so you can have it in there plain as day.Quick recap now at this point the regex matches any two digit number followed by a capital
WNow the rest of the regex is easy to figure out, because the hyphen again isn’t a special char, and you already know what the square brackets are doing.