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

  • SEARCH
  • Home
  • 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 82381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:36:29+00:00 2026-05-10T21:36:29+00:00

I want to match a block of code multiple times in a file but

  • 0

I want to match a block of code multiple times in a file but can’t work out the regular expression to do this. An example of the code block is:

//@debug ... // code in here ... //@end-debug (possibly more comments here on same line) 

Each code block I’m trying to match will start with //@debug and stop at the end of the line containing //@end-debug

I have this at the moment:

/(\/{2}\@debug)(.|\s)*(\/{2}\@end-debug).*/ 

But this matches one big block from the first //@debug all the way to end of the line of the very last //@end-debug in the file.

Any ideas?

  • 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. 2026-05-10T21:36:29+00:00Added an answer on May 10, 2026 at 9:36 pm

    Basically your regular expression is greedy. This means the wildcard operators grab as much as they possibly can with the results you’ve seen. Just change it to non-greedy where appropriate. In your case use:

    /(/{2}\@debug)(.|\s)*?(/{2}\@end-debug).*/

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

Sidebar

Related Questions

I want to match D11-RONPLAYER_DEF_15_PO using this regular expression: D\[0-9]+-\[A-Z]*PLAYER_(DEF\[0-9]*)_(\[^_]+)_ but it does not
I want to match links like <a href=mailto:my@email.com>foo</a> , but this doesn't work only
I can't get my regex to match the header of a c# code file.
I want to match all URLS but exclude image urls from beeing matched with
I want to match all the lines in a file either starting with 0D
I want to match all lines that have any uppercase characters in them but
This is probably basic to most reading, but I can't seem to figure it
regex not working as wanted Code example: widgetCSS = #widgetpuffimg{width:100%;position:relative;display:block;background:url(/images/small-banner/Dog-Activity-BXP135285s.jpg) no-repeat 50% 0; height:220px;}
I know there's a wizard out there who can answer this ... I have
How can I match a block of text that is indented using tabs? Say

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.