0

I have a big pieces of code, so I want to find a regular expression to find all places where my code does not have engineer in the comment before the public or private, for example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    /// <summary>
    /// Blah blah
    /// </summary>
    /// engineer: blehbleh
    public class Class1
    {
        /// <summary>
        /// constructor
        /// </summary>
        /// engineer: mme
        public Class1()
        {

        }

        /// <summary>
        /// get data
        /// </summary>
        /// <param name="i">i param</param>
        /// <returns>o param</returns>
        public int GetData(int i)
        {
            return i;
        }
    }
}

In this case the regular expression should return public int GetData(int i) because do not have engineer before it.

Any advice? of course it should support multi line, notepad++ or expresso regex are ok.

jrpz
  • 73
  • 1
  • 8

1 Answers1

1

You may use

^(?![ \t]*///[ \t]*engineer).*[\r\n]+\s*((?:public|private).*)

See the regex demo

Details

  • ^ - in text editors, start of a line
  • (?![ \t]*///[ \t]*engineer) - no 0 or more spaces or tabs followed with ///, 0 or more spaces or tabs and then engineer is allowed immediately to the right of the current location
  • .*[\r\n]+ - a line with line ending sequence
  • \s* - 0+ whitespaces
  • ((?:public|private).*) - Group 1: either public or private and then the rest of the line.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563