none
Regular expressions RRS feed

  • Question

  • Hi,

    I need a regular expression that allows only below characters 

    0-9
    A-Z upper case
    a-z lower case (if there is anything lower case, conver to upper case)
    space
    [
    ]
    '
    {
    }
    |
    _

    !
    "
    #

    %
    &
    (
    )
    +
    -
    .
    /
    ,
    carriage return and new line feed (\r and \n)

    Thank You

    Friday, August 31, 2018 3:19 PM

Answers

  • Use Regex Editor Lite (VS Extension) or similar tool to help you create regular expressions. Note that REs aren't always the best solution. In an RE letters and digits are represented as \w. The remainder of the characters are listed as is with special characters (parens, brackets, etc) needing to be delimited. For example the following would match identifiers (starts with letter and is followed by zero or more letters, digits or underscores).

    [a-z](\w_)*
    Setting the RegexOptions to IgnoreCase will cause case to not matter. You'll have to explicitly convert lower case characters to upper (String.ToUpper) if you want that in the results. RE doesn't modify stuff.



    Michael Taylor http://www.michaeltaylorp3.net

    Friday, August 31, 2018 5:07 PM
    Moderator