Regex to find occurrences of one word before the other

6

I need to find in the system fonts situations where TAction occurs after TdxBar .

This will happen on different lines, but within the same file.

for example

pnlVisao: TPanel;
tbToolBar: TdxBar;
btnCancelar: TButton;
actAbrir: TAction;

In this case the action is declared after the toolbar

I tried to use /(TdxBar)(?=TAction)/g but it did not work

    
asked by anonymous 12.03.2015 / 15:10

2 answers

9

I've researched a flag to use in Sublime that makes regex multiline.

Try Regex (?s)TdxBar.*?TAction . The (?s) tells Sublime that regex is multiline causing . to also match with line breaks.

link

Edit (2018-09-19)

I recently ran into explanations on the internet and decided to supplement this answer.

This post in the Sublime forum on a new < in> engine for regex implemented in the software. The creator of the package control responds that the new engine is used for syntax highlight and reading the post discovers that the library Oniguruma is used in Sublime Text.

Entering the repository, I found where the (?s) flag is documented : / p>

+ ONIG_SYNTAX_PERL and ONIG_SYNTAX_JAVA
    (?s): dot (.) also matches newline
    (?m): ^ matches after newline, $ matches before newline
    
12.03.2015 / 15:25
3

If the intention is to find the list of files that contain the aforementioned pattern suggested:

grep  -zPl 'TdxBar(.|\n)*TAction' *
  • -z The -z (null separated records) option causes the file to be loaded as if it were a single line; so regular expressions can be multilingual
  • -l tells only the names of files that contain instances of the default
  • -P regular expressions extended in Perl syntax
12.03.2015 / 19:36