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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:29:26+00:00 2026-06-07T22:29:26+00:00

I have several classes that I need to format. I need to place the

  • 0

I have several classes that I need to format. I need to place the using directives inside the namespace. In other words I have to change:

// some comment about system
using System;
using System.Collections.Generics; // needed to create lists

namespace MyNamespace
{
     ... code

into:

namespace MyNamespace
{

     // some comment about system
     using System;
     using System.Collections.Generics; // needed to create lists

     ... code

So in short I will like to be able to match:

// some comment about system
using System;
using System.Collections.Generics; // needed to create lists

what I have worked so far is this regex: (?s)(//.*?(?=\r))(\r\n|^)*using .*?;

the first group (//.*?(?=\r))(\r\n|^) matches a comment. so if the using has a comment I will like to take that comment also. Note that I placed a * at the end of the group in order to have 0 or more comments. for some reason the second using is not matched why?

  • 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-07T22:29:27+00:00Added an answer on June 7, 2026 at 10:29 pm

    IF you where to have something like:

    // comment goes here
    using System.Text.RegularExpressions; // for regexes
    using System.Text; /* comment */
    using System.Collections.Generic; // som comment
       /* this is a long comment
           that spans multiple lines
           in order to explain this using */
    using System.Foo;
    
    
    
    
    namespace EncloseCodeInRegion
    {
    

    the regex:

    (((//.*?\r\n)|( */\*[\s\S]*?\*/))?(\r\n)? *using .+?;(( *//.*(?=\r))|( */\*[\s\S]*?\*/))?)(?=[\s\S]*?namespace)
    

    would match the all the using statements.

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

Sidebar

Related Questions

I have several BusinessObject classes that refer to each other and I need to
I have several classes that need to load some properties files, and I was
I have some methods that are used by several classes. My idea was to
I have several classes that extend C and I would need a method that
I have interface IModule and several classes that implements it. In test i need
I have several modules (mainly C) that need to be redesigned (using C++). Currently,
I have several classes that do not really need any state. From the organizational
I have several complex classes, that are constructed using separate creator classes that inherits
I have a need for methods in several classes that must always follow a
This is for a web project so i have several classes that inherit from

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.