IDE regular expressions

From Lazarus wiki
Jump to navigationJump to search

Normal regular expression

They are pretty similar to Perl regular expression syntax.

Point .

Matches any character. Example: 'a.c' matches 'abc', 'aBC', 'axc', 'a3c', 'a$c', etc.

Round brackets ( )

Useful to bound expressins. For example: (abc)+ matches 'abc' or 'abcabc' or 'abcabcabc' etc.


Simple Syntax

Some IDE dialogs provide a checkbox to enable 'simple syntax'. These regular expressions are shorter for common file name filters.

Technically it does this:

  The following characters are replaced with
  . -> \.
  * -> .*
  ? -> .
  , -> |
  ; -> |
  
  Finally enclose by ^( )$


Search and Replace with regular expressions

The find dialogs support regular expressions for finding and replacing. For example:

  • Find expression: a(.*)c
  • Replace expression: A$1C
  • Text: 'abc aLazc'

The $1 will be replaced with the found text, that matches the first bracket.

  • Result: 'AbC ALazC'