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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:11:33+00:00 2026-05-17T19:11:33+00:00

someText 1 2 3 4 moreText I would like to add a prefix before

  • 0
someText
1
2
3
4
moreText

I would like to add a prefix before each digit.

but using (\w+\R)(\d+\R)+(\w+) and \1prefix\2\3 will only prefix the last digit and erase the others.

Is there a way to do it with a single regex or should i write a script on the side?

  • 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-17T19:11:34+00:00Added an answer on May 17, 2026 at 7:11 pm

    The problem with your regex is the use of greedy matching in the (\d+\R)+, specifically the last +. That reads, “match this group as many times as you can so long as it doesn’t cause the miss of a match”. So for your text it gobbles up 1, 2, 3, and 4 before it can’t gobble any more and puts the last match into the second capture group. Obviously, it’s in the nature of regex engines to be unable to express variadic groups, how would you address them anyway? So the short answer, I think is that regexes are the wrong tool for a fully automated process and you’ll have to write a script.

    However, for a slightly less automated process that still incorporates your surrounding text, you could try

    find: (\w+\R)((?:\d+\R)+)(\w+)
    replace: \1prefix\2\3
    

    We wrap the second group plus it’s greedy modifier in an extra set of capturing parens and enclose the actual matching text in a non-capturing group. Now, we have the full set of digits in their own group and can add the prefix to the first one. The interesting side effect of this is that the first number then matches the first group (\w+\R) and if you run the find/replace again it hits the next number in the line until it no longer matches.

    This way, you should be able to run through your files at least only hitting the areas you are interested in adding this prefix to and it shouldn’t take nearly as long as finding every digit in every file.

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

Sidebar

Related Questions

I would like to remove a tag from some HTML without stripping the remaining
I would like to know if there is a method for splitting a jQuery
So basically, I have a string like this: Some Text Here | More Text
I'm trying to understand block container boxes as described in the CSS2.1 spec, but
Hello I am using the following code to linkify email addresses and urls and
How can I have Flash reading XML ignore white spaces that would be ignored
I have been given some html that look like this (I have no control
I have a mysql query which outputs 6 columns of related data, I'm specifically
I'm presenting text in a wpf TextBlock control (.Net 3.5). The content of the
I understand since Regex is essentially stateless, it's rather difficult to achieve complicated matches

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.