Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:45:33+00:00 2026-06-05T07:45:33+00:00

I am trying to remove all the vowels from a string except for the

  • 0

I am trying to remove all the vowels from a string except for the first and last character. I have tried with 2 expressions and using 2 ways but in vain. I have described them below. Does anybody has a regular expression for this?

e.g.

original string — source = apeaple

after regex — source_modified = apple (this is what is expected)

I tried the expression ([a-zA-Z])[aeiouAEIOU]([a-zA-Z]) but this expression is removing repeated character as well. So the following is happening when i apply the above expression

code used —

Regex reg = new Regex("([a-zA-Z])[aeiouAEIOU]([a-zA-Z])");
string source_modified = reg.Replace(source, "");

original string — source = apeaple

after code execution — source_modified = aple (repeating character removed)

code used — string source_modified = Regex.Replace(source, "([a-zA-Z])[aeiouAEIOU]([a-zA-Z])", "$1" + "$2");

original string — source = apeaple

after code execution — source_modified = apaple (just 1 vowel gets removed)

i also tried ([a-zA-Z])[aeiouAEIOU]*([a-zA-Z]) but this is removing just 1 vowel and not all. So the following is happening when i apply the above expression

code used —

Regex reg = new Regex("([a-zA-Z])[aeiouAEIOU]*([a-zA-Z])");
string source_modified = reg.Replace(source, "");

original string — source = apeaple

after code execution — source_modified = “” (all characters are removed)

code used — string source_modified = Regex.Replace(source, "([a-zA-Z])[aeiouAEIOU]*([a-zA-Z])", "$1" + "$2");

original string — source = apeaple

after code execution — source_modified = apeple

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:45:35+00:00Added an answer on June 5, 2026 at 7:45 am

    You need some lookaround like so

    (?<!^)[aouieyAOUIEY](?!$)
    

    C# supports it and it’s very powerful

    string resultString = null;
    try {
        resultString = Regex.Replace(subjectString, "(?<!^)[aeui](?!$)", "");
    } catch (ArgumentException ex) {
        // Syntax error in the regular expression
    }
    

    Update 1

    T.W.R.Cole informs me that there is a special rule in the English language (“this doesn’t work for words like “Anyanka” where an inner ‘y’ is used as a consonant”)

    The following change should do this, using the technique of negative lookahead:

    (?<!^)([aouie]|y(?![aouie]))(?!$)
    

    This time enable the regex modifier that matches case insensitive, it makes the regex simpler than the original

    if a y followed by another y still means that the y is a consonant (euh… is there such a word) and thus should not disappear than a y must be listed in the last character class as well :

    (?<!^)([aouie]|y(?![aouiey]))(?!$)
    

    I repeat that I used C# as my regex dialect which has good support for lookaround techniques.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove all of a specific character from a string. I
I'm trying to remove all non numeric characters from string except for x. I'm
I'm trying to remove all but the first child component from a Java Container.
I am trying to remove all HTML elements from a String. Unfortunately, I cannot
I am trying to remove all the non-word character in a string, but want
I'm trying to remove all BBCode Tags from a string. [url]www.google.com[/url] becomes www.google.com I
I'm trying to remove a specific word from a certain string using the function
I'm trying to remove all the spaces from a string derived from user input,
I was trying to remove all the lines of a file except the last
With Regular Expressions I'm trying to remove all the methods/functions from the following code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.