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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:31:35+00:00 2026-06-05T05:31:35+00:00

So I am try to write a script that will turn a to an

  • 0

So I am try to write a script that will turn a to an (when necessary). And it is harder than I thought.

var txt = "This is a apple.";

var pos = txt.search(/a\s[aeiou]/i);
txt = pos != -1 ?
      txt.substring(0,pos+1) + "n" + txt.substring(pos+1,txt.length) :
      txt;
//"This is an apple."

It is working, but when I try "There are 60 minutes in a hour.", it didn’t not change it into an because of the regex. So I changed it:

var pos = txt.search(/a\s([aeiou]|hour)/i);

Now it is working (at least for “hour”). But now if I put "There are people in a university.", it will change it into an university, which is not correct.

So, is there a regular expression that can cover the rules of using a and an in the English language? Thanks!

  • 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-05T05:31:37+00:00Added an answer on June 5, 2026 at 5:31 am

    There was a very good thread about this on StackOverflow a while ago: How can I correctly prefix a word with "a" and "an"?

    Basically the consensus was that the best way involves a large dataset from which to learn, and the second-best way involves a pronunciation dictionary such as the CMU dict designed for speech synthesis.

    To give an example from the CMU dict:

    University comes out as:
    Y UW N AH V ER S AH T IY . 
    
    Umbrella is rendered as:
    AH M B R EH L AH . 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to write a script that will reset and reinitialize the database for
I am trying to write a script that will look through a set of
I would like to write a script that will tell another server to SVN
I'm trying to write a PowerShell script that will do the following: Executes a
I'm trying to write my first semi advanced bash script that will take input
I am trying to write a PS script that will open a stored proc,
I'm trying to write a php script that will generate a variety of new
I want to write a Powershell script that will validate a large number of
I wish to write a simple git script that will run the following lines:
I'm attempting to write a Twitter Powershell script that will use community created interfaces

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.