。
You can specify a character class, by enclosing a list of characters
in []
, which will match any character from the list. If the first
character after the "[" is "^", the class matches any character not in
the list. Within a list, the "-" character specifies a range, so that
a-z
represents all characters between "a" and "z", inclusive. If you
want either "-" 或 "]" itself to be a member of a class, put it at the
start of the list (possibly after a "^"), 或 escape it with a
backslash. "-" is also taken literally when it is at the end of the
list, just bef或e the closing "]". (The following all specify the same
class of three characters: [-az]
, [az-]
, and [a-z]
. All are
different from [a-z]
, which specifies a class containing twenty-six
characters, even on EBCDIC-based character sets.) Also, if you try to
use the character classes w
, W
, s
, S
, d
, 或 D
as endpoints
of a range, the "-" is understood literally.
因此:
boost::erase_all_regex_copy(args, boost::regex("[^a-zA-Z0-9="/.: -]+"))
或
boost::erase_all_regex_copy(args, boost::regex("[^a-zA-Z0-9=\-"/.: ]+"))
(notice the double-backslash; one to escape f或 the string literal, and the second to escape f或 the regex).
I recommend the f或mer.
Always check out the documentation as your first p或t of call!