Regular expression to match IRC nickname
问题 How would I use a regular expression to match an IRC nickname? This is being done in Ruby if that makes a difference (it probably will, with the syntax of the regex, but who knows.) EDIT: An IRC nickname can contain any letter, number, or any of the following characters: < - [ ] \ ^ { } 回答1: # If you are testing a single string irc_nick_re = /\A[a-z_\-\[\]\\^{}|`][a-z0-9_\-\[\]\\^{}|`]*\z/i # If you are scanning them out of a larger string irc_nick_re = /(?<=[^a-z_\-\[\]\\^{}|`])[a-z_\-\[\]\\