New Ruby questions

A bit less more complex, but more precise; matches up to “r42”

rough translation: "match an ‘r’, followed by either the a digit

followed by a non-digit; or a number 1-3 followed by one digit

and a non-digit; or the number 4 followed by a 0, 1, or 2.

register_regex = /r(?:\d\D|[1-3]\d\D|4[012]\D)/

That doesn’t work if the register is at the EOF (is that important?).

/\br([1-3]+\d|4[012])\b)/

\b == word boundary
( == begin brackets for the boolean expression
[123]+\d == any digit, optionally preceded by 1,2 or 3 (ie 0
thru 39)

           == or

4[012] == 4 followed by 0,1 or 2 (40 thru 42)
) == end boolean expression
\b == word boundary

···

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################

A bit less more complex, but more precise; matches up to “r42”

rough translation: "match an ‘r’, followed by either the a digit

followed by a non-digit; or a number 1-3 followed by one digit

and a non-digit; or the number 4 followed by a 0, 1, or 2.

register_regex = /r(?:\d\D|[1-3]\d\D|4[012]\D)/

That doesn’t work if the register is at the EOF (is that important?).

oops :slight_smile: nice catch; \D will consume the character it matches, \b is
zero-width and doesn’t match a character, just the space between two
characters…

···

On Apr 13, 2004, at 4:39 PM, Daniel Sheppard wrote:

/\br([1-3]+\d|4[012])\b)/

\b == word boundary
( == begin brackets for the boolean expression
[123]+\d == any digit, optionally preceded by 1,2 or 3 (ie 0
thru 39)

           == or

4[012] == 4 followed by 0,1 or 2 (40 thru 42)
) == end boolean expression
\b == word boundary