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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:42:06+00:00 2026-05-26T22:42:06+00:00

How do I create a regex that begins matching where it starts searching ?

  • 0

How do I create a regex that begins matching where it starts searching?

In other words:

What is the equivalent of \A which says, “match at the start of the search, even if it’s not in the beginning of the main string”?

new Regex(@"\A\n").IsMatch("!\n", 1);    // Should be true, but is false
  • 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-05-26T22:42:07+00:00Added an answer on May 26, 2026 at 10:42 pm

    What you’re looking for is \G:

    new Regex(@"\G\n").IsMatch("!\n", 1);    // It's twue, it's twue!
    

    This was a surprise to me, actually. I knew about \G, but it’s usually described as an anchor that matches the beginning of the input or the end of the most recent successful match, neither of which applies here. If this is a .NET innovation, they should make more noise about it; it looks like it could be very handy.

    EDIT: Come to think of it, Java’s find(int) does work the same way–I’ve even used it extensively. But then they added the “regions” API in Java 5, which offers much finer control, and I forgot about this idiom. I never thought to look for it in .NET.

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

Sidebar

Related Questions

I'd like to create a regex that will match an opening <a> tag containing
I have a string on which I try to create a regex mask that
I want to create a regex that match '.', '#' and ':' and also
I'm trying to create a regex that will match only when the string has
I am attempting to create a regex that will match all uppercase letters before
I am trying to create a regex that does not match a word (a-z
I am trying to create a regex that will match the first 3 characters
I want to create a regex that will match any of these values 7-5
I'm trying to create a regex that will match the following: http://myurl.com/en/something I need
I need to create a regex that do the matching of 2 chars: &

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.