RegEx to determine if a row ends in a semi-colony

I am trying to run some code files and find lines that do not end with a semicolon.

I currently have this: ^(?:(?!;).)*$from the Googling group, and everything works fine. But now I want to expand it so that it ignores all spaces at the beginning or specific keywords, such as a package or opening and closing curly braces.

The ultimate goal is to take something like this:

package example
{
    public class Example
    {
        var i = 0

        var j = 1;

        // other functions and stuff
    }
}

And for the template to show me that there is var i = 0no partial shade. This is just an example; a missing half-raft can be anywhere in the class.

Any ideas? I trained for more than an hour, but no luck.

Thank.

+5
source share
6 answers

Try the following:

^\s*(?!package|public|class|//|[{}]).*(?<!;\s*)$

PowerShell:

PS> (gc file.txt) -match '^\s*(?!package|public|class|//|[{}]).*(?<!;\s*)$'
        var i = 0 
PS> 
+1

, , .*, , [^;], , , \s* $. , :

.*[^;]\s*$

, , ^, , [^\s], :

^[^\s].*[^;]\s*$

, package , , class, , , . , , (?:\s|package|class), , -, , (?!\s|package|class). !. , :

^(?!\s|package|class).*[^;]\s*$
+1

, , / :

  • lookbehind
  • lookbehind

, , , , , , .

str.scan(/^\s*(?=\S)(?!package.+\n|public.+\n|\/\/|\{|\})(.+)(?<!;)\s*$/)
+1

, , :

.*[^;]$

, :

^[^ ].*[^;]$
0

, , , whitespace ^\s*, , (?!package|class), - .*, ( ) [^;]\s*.

^\s*(?!package|class).*?[^;]\s*$

, .

0

, , Java, , java, . vim .

\(.\+[^; ]$\)\(^.*public.*\|.*//.*\|.*interface.*\|.*for.*\|.*class.*\|.*try.*\|^\s*if\s\+.*\|.*private.*\|.*new.*\|.*else.*\|.*while.*\|.*protected.*$\)\@<!
   ^          ^                                                                                                                                           ^
   |          |                                                                                                                 negative lookbehind feature 
   |          |
   |          2.  But not where such matches are preceeded by these keywords
   |
   |
   1. Group of at least some anychar preceeding a missing semicolon

:

^          beginning of line
.*         Any amount of any char
+          at least one
[^ ... ]   everything but
$          end of line
\( ... \)  group
\|         delimiter
\@<!       negative lookbehind

:

, / . , , java, java- , , .

, , :

enter image description here

, :

https://jbodah.imtqy.com/blog/2016/11/01/positivenegative-lookaheadlookbehind-vim/

0
source

All Articles