[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

regular expression to discard consecutive consonants

how would I write a regular expression that would eliminate consecutive consonants from a word and spit out the rest of the word minus the deleted consonants? ie hello would become helo, butterfly would become buter?

thanx!
0
jade03
Asked:
jade03
  • 2
  • 2
  • 2
  • +1
1 Solution
 
WoodsterCommented:
you will need to loop through each character within the string and test if the next character in the same string is the same character, if so, skip to next character else write the tested character to a new string

ie:

char * stripDuplicates(char *source, char *target)
{
  // Loop through all characters in source.
    // Is current character in source string equal following character (current character  + 1) in source string
      // If not the same then add current character to target string

  return target;
}
0
 
jade03Author Commented:
can I grab individual characters from yytext? the way i understand it, is yytext holds the token found from a regular expression...so if the token is the word "friends" then can I assume yytext[0] contains "f", yytext[1] contains "r" etc?
0
 
WoodsterCommented:
I am not entirely sure what yytext is but I am guessing it is a char *.  In this case, each individual character can be accessed either by:

yytext[position]

or by

*(yytext + position)

either method will return the indivdual character at position, where 0 is the first character.

Eg:

yytext[0] = 'f'
yytext[1] = 'r'

*yytext = 'f'
*(yytext + 1) = 'r'

etc...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
manav_mathurCommented:
you have to run a loop like

for(i=0;i<strlen(yytext)-1;i++)
{
    if "yytext[i] is a consonant" && "yytext[i+1] is a consonant"
        //left shift yytext array from i+1 th position till the last
}

Manav
0
 
jhshuklaCommented:
>> left shift yytext array from i+1 th position till the last
that's a complex and expensive operation. I suggest maitaining one index for reading and one for writing.
0
 
jade03Author Commented:
thanx guys! it seems to work! :)
0
 
manav_mathurCommented:
> that's a complex and expensive operation. I suggest maitaining one index for reading and one for writing.

suits me just fine, if it suits the author.

Manav
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now