re = /[!-\/:-@[-`{-~]/m
str = ' ! U+0021 EXCLAMATION MARK
" U+0022 QUOTATION MARK
# U+0023 NUMBER SIGN
$ U+0024 DOLLAR SIGN
% U+0025 PERCENT SIGN
& U+0026 AMPERSAND
\' U+0027 APOSTROPHE
( U+0028 LEFT PARENTHESIS
) U+0029 RIGHT PARENTHESIS
* U+002A ASTERISK
+ U+002B PLUS SIGN
, U+002C COMMA
- U+002D HYPHEN-MINUS
. U+002E FULL STOP
/ U+002F SOLIDUS
: U+003A COLON
; U+003B SEMICOLON
< U+003C LESS-THAN SIGN
= U+003D EQUALS SIGN
> U+003E GREATER-THAN SIGN
? U+003F QUESTION MARK
@ U+0040 COMMERCIAL AT
[ U+005B LEFT SQUARE BRACKET
\\ U+005C REVERSE SOLIDUS
] U+005D RIGHT SQUARE BRACKET
^ U+005E CIRCUMFLEX ACCENT
_ U+005F LOW LINE
` U+0060 GRAVE ACCENT
{ U+007B LEFT CURLY BRACKET
| U+007C VERTICAL LINE
} U+007D RIGHT CURLY BRACKET
~ U+007E TILDE'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html