none
RegEx RRS feed

  • Question

  • Hello,

    What is the regular expression for entering :

    1-
    one character either Y or N --> either small or capital letter

    Thank you

    Thursday, January 25, 2018 12:37 PM

Answers

  • The (?i) bit means that everything afterwards will be case-insensitive.

    Of course, you could also just use [YNyn], which you may find simpler:

    Regex rgx = new Regex("^[YNyn]$");


    • Edited by RJP1973 Thursday, January 25, 2018 1:05 PM
    • Marked as answer by arkiboys Thursday, January 25, 2018 1:14 PM
    Thursday, January 25, 2018 12:51 PM

All replies

  • (?i)[YN]
    The "(?i)" bit means case-insensitive. Alternatively you can specify the 'IgnoreCase' option when you create the RegEx object.
    Thursday, January 25, 2018 12:42 PM
  • Hi,
    I managed to work-out ^[YN]$

    But this is not case sensitive

    Thursday, January 25, 2018 12:47 PM
  • The (?i) bit means that everything afterwards will be case-insensitive.

    Of course, you could also just use [YNyn], which you may find simpler:

    Regex rgx = new Regex("^[YNyn]$");


    • Edited by RJP1973 Thursday, January 25, 2018 1:05 PM
    • Marked as answer by arkiboys Thursday, January 25, 2018 1:14 PM
    Thursday, January 25, 2018 12:51 PM