Similar to this question but with a difference subtle enough that I still need some help.
Currently I have:
'(.*)\[(\d+\-\d+)\]'
as my regex, which matches any number of characters followed by square brackets [] that contain two decimals separated by a dash. My issue is, I’d like it to also match with just one decimal number between the square brackets, and possibly even with nothing in between the square brackets. So:
word[1-5] = match
word[5] = match
word[] = match (not essential)
and ensuring
word[-5] = no match
Could anyone possibly point my in the direction of the next step. I currently find regex to be a bit of a guessing game though I would like to become better with them.
Go with yours and make the last part optional
Using
?.To accomplish the other task, well, go with
?againA working example http://rubular.com/r/t0MaHyHfeS