Consider the following strings:
hotpoint nm11 823 wk eu n 1200 rpm 8 kg class a+++
hotpoint nm11 823 wk eu n rpm 1200 8 kg class a+++
hotpoint nm11 823 wk eu n rpm1200 8 kg class a+++
How could I write a regexp, that will match the highlighted part in either string? Basically, I want a regexp that will match part of a string that either starts with rpm
or ends with rpm
and contains only spaces and numbers in between.
To do a regexp that starts with rpm
and contains only numbers or spaces, I could do something like this:
/((rpm)\s{0,1}(\d+))/
and I also know that I can achieve the desired result by adding an additional | (OR)
part to the regexp by this:
/((rpm)\s{0,1}(\d+)|(\d+)\s{0,1}rpm)/
What I am interested in, if there is any other way to specify that the matched part should either start or end with something specific, without duplicating the whole matching rule?
Note, that the part of the string I am looking for is not on the end or the beginning of the string, so I can't use $
or ^