none
Regex - matching world which contain only vowels or consonants RRS feed

  • Question

  • Hi   ,

    Could any body  help me,

    I have to check a string either Vowels or Consonants.

    I got RegExp:  " 

    ^[aeyiuo]*$|^[^aeyiuo]*$"

    if string contains Either NG or Y then it should not match .

    How I can add  above condition .

    Tuesday, September 23, 2014 3:05 PM

Answers

  • If you mean the upper case strings "NG" and Y":

    Regex reg = new Regex("^[aeyiuoAEIOU]*$|^(?!.*NG).[^aeyiuo]*$");

    If you mean the case insensitive strings "ng" and "y":

    Regex reg = new Regex("^[aeiuoAEIOU]*$|^(?!.*(NG|ng)).[^aeyiuo]*$");
    

    Please remember to mark helpful posts as answer and/or helpful.
    • Marked as answer by mkonanki Tuesday, September 23, 2014 4:08 PM
    Tuesday, September 23, 2014 3:40 PM

All replies

  • If you mean the upper case strings "NG" and Y":

    Regex reg = new Regex("^[aeyiuoAEIOU]*$|^(?!.*NG).[^aeyiuo]*$");

    If you mean the case insensitive strings "ng" and "y":

    Regex reg = new Regex("^[aeiuoAEIOU]*$|^(?!.*(NG|ng)).[^aeyiuo]*$");
    

    Please remember to mark helpful posts as answer and/or helpful.
    • Marked as answer by mkonanki Tuesday, September 23, 2014 4:08 PM
    Tuesday, September 23, 2014 3:40 PM
  • Thank u so much  for you help.  Great  answer .

    Regex reg = new Regex("^[aeiuoAEIOU]*$|^(?!.*(NG|ng)).[^aeyiuo]*$");

    Tuesday, September 23, 2014 4:09 PM