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 8370661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:57:59+00:00 2026-06-09T13:57:59+00:00

I was pretty surprised I couldn’t find this anywhere online, including stackoverflow. I’m looking

  • 0

I was pretty surprised I couldn’t find this anywhere online, including stackoverflow. I’m looking for the regex to use in the PHP function preg_replace to achieve this:

Find any part of the text where ” a ” is followed by a vowel, and convert the ” a ” to ” an “, following the English grammar rule.

For example:

” a apple” will be converted to ” an apple”.

” a igloo” will be converted to ” an igloo”.

etc. etc.

Ideally, the function would be case-insensitive. What would be really impressive is if it could preserve the original case, e.g. “A” would be converted to “An”, and the case of the next word would be left alone, e.g. “an American” wouldn’t end up as “an american”.

This seems like exactly the sort of thing a regex would be ideal for, and that a lot of people would find useful, but I can’t figure it out. Would be grateful for some help with this.

I’m currently trying this:

preg_replace("/ a?i ([aeio])?i/", "an $1", $string)

As commenters have rightfully pointed out, this won’t completely solve the problem of a / an, as that’s based on sound and not just letters. However, I still think it’s worthwhile on an “every little helps” basis, as it corrects the majority of such issues and so saves some human editing time.

  • 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-09T13:58:00+00:00Added an answer on June 9, 2026 at 1:58 pm

    My pattern is as follows, though the issue (re: u) in the comments above is way trickier.

    preg_replace('/\b(a)\s+([aeiou])/i', '$1n $2', $source_string);
    

    Of course, you could take a gamble if u is the only trouble letter, and trust the source string in the case where u follows, simply remove it from the pattern: /\b(a)\s+([aeio])/i

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

Sidebar

Related Questions

I'm surprised I couldn't find an answer to this anywhere. I'm writing a roguelike
Pretty basic question ... I can not find the compatibility table (was looking at
I'm surprised this question wasn't asked before on SO (well, at least I couldn't
I was surprised when I just tried the following PHP code: function foo() {
I need to build a family tree in php and MySQL. I'm pretty surprised
I am surprised I could not find a "batch" function that would take as
I'm pretty new to ajax, so I'm surprised that this doesn't work or error
I was pretty surprised when i saw http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg link not give me a download
I am pretty new to silverlight and was very surprised to see that only
Pretty confused right now, while i feel i know a bit about vhosts this

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.