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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:45:07+00:00 2026-06-07T21:45:07+00:00

This is an oft repeated question, but somehow I didn’t find the previous answers

  • 0

This is an oft repeated question, but somehow I didn’t find the previous answers exactly matching my requirement. There is a string

My name is Pavan. Am I a good boy?

I want to match only the first occurrence of the character a(irrespective of whether its at a word boundary or not ) in the above string. The simplest regex

a

will match all four as present in the string. All the other posts I searched on SO are suggesting using non-greedy match ?. But a+? doesn’t solve the problem here as even the non-greedy match would be repeated 4 times.

So how shall I tell the regex engine to stop soon after the first match?

I might have asked a very trivial question, but bear with me as I’ve just started with regexes.

PS: I am using the following 2 engines to verify my results

GSkinner

RegexPal

I am not using any specific language and am just using the above tools to perform matches

  • 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-07T21:45:10+00:00Added an answer on June 7, 2026 at 9:45 pm

    You’re confusing quantifiers in the regex language with the tools your language/framework gives you. Usually there is a method that returns all matches and one that returns only the first match (and one that just checks whether a regex matches).

    In .NET Regex.Matches finds all matches, Regex.Match finds just the first one and you can use Regex.IsMatch to figure out whether a regex matches.

    In Java you can use Matcher.find to find the first match or iterate to find all.

    In Python there is re.search and re.findall.

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

Sidebar

Related Questions

I know this is an oft asked question, but I've tried some of the
This must be an oft-answered question, but my google-foo fails me. Take a look
This is probably a stupid question, but how much of a security risk is
I know this is an oft-asked question/problem. I've looked through a bunch of Q&A
This is just a Translation question. But how do you write a the following
Is the advice given in this oft-cited MSDN article still considered sound for converting
There's this ... MSDN page, IQueryable(Of T) Interface . Can you do a better
This somehow simple task is not so simple. I can get the number of
This should be simple, but the answer is eluding me. If I've got a
this is my code that I write it but I want to use LINQ

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.