1

I wrote a small program that converts English text into a Pig Latin in Visual Basic. I am currently converting it into C# language. And during the conversion process, I am stumbling upon a regex-related error.

The rules I am working with are:

  • String starts with a, e, i, o, or u
  • String contains a, e, i, o, u, or y

In VB, I wrote those rules as following (both variables are bool):

isVowel = words(counter) Like "[aeiou]*"
isInside = words(counter) Like "*[aeiouy]*"

Where Private index As Integer = -1 Private words(index) As String.

And the For loop

For counter As Integer = 0 To words.Length - 1
    isVowel = words(counter) Like "[aeiou]*"
    isInside = words(counter) Like "*[aeiouy]*"

    //proceed with conversion logic
Next counter

Upon research, I used the following article as a reference to help with conversion. I ended up converting those lines as following:

isVowel = Regex.IsMatch(words[counter], "[aeiou]*");
isInside = Regex.IsMatch(words[counter], "*[aeiouy]*");

Now I am testing both of these rules on my first string in the text, which is adam. In VB, for the first letter a both isVowel and isInside return true. For C#, isVowel returns true, but isInside returns the following error instead of true as I hoped for:

Quantifier {x,y} following nothing

I searched threads here in SO (those were case specific, but I tried using its answers as possible pointers) along with SO wiki it suggested. I tried updating the rule based on what I learned from wiki and this thread (and this one, I'll use just a couple to link out of 10+ threads that I found) about *, +, and ?. I tried using both + and ? on preceding character pattern. But it returns the same error.

Can you please point me in the right direction of why this rule returns the error? Am I missing something regex C#-specific?

Community
  • 1
  • 1
Vadzim Savenok
  • 930
  • 3
  • 14
  • 37

0 Answers0