About the program

RegExp

RegExp is a program designed to test regular expressions, but does not exclude data processing. It has several libraries with ready-made regular expressions for solving some parsing tasks. The program is only a shell, parsing (parsing) is performed by the PCRE engine. The program is written based on the RegExp program I wrote earlier on AutoIt3

Version 0.5.2 from 2022
Author AZJIO
Site http://azjio.ucoz.ru
Discussion:
  • azjio.ucoz.ru
  • purebasic.fr
  • purebasic.mybb.ru
  • usbtor.ru
  • puppyrus.org

Original text

Contribute a better translation


License

Software license

The program is free

For use "as is", the responsibility for misuse lies with the user.

The program can be included in a commercial project, but without increasing the cost due to the program, since it is free. This allows use in any assembly as an additional tool.

source license

You may only modify the source for your own use.

Permission is granted to study and use parts of the code.

It is forbidden to redistribute the upgraded version.

It is forbidden to change the "About" dialog.

For any questions not listed here, please contact the author to discuss the conditions.

Original text

Contribute a better translation


Regular Expressions

Metacharacters outside square brackets

( ) - the beginning and end of the group, for example (text). Mean a sequence. They are used to apply quantifiers not to one character, but to several, as well as to further use the found sequence.
[ ] - beginning and end of character class description, for example [az]. The character class returns one character from a set. Repeaters can change this.
{ } - start and end of repeaters, eg {3,8}
\ - escape character, accept metacharacter as a regular character, eg (\\, \., \[, \], \{, \}, \*).
^ - start of line (or start of text in multiline texts with (?m) flag), e.g. ^text text$
$- end of line (or end of text in multiline texts with (?m) flag), for example ^text text$
. - any character except line break @LF (default). With flag (?s) - any character
| - the "or" character, usually within a group, eg (10|20)
? - the previous character is either available or not available, similarly for groups. After the repeat character - pattern greed - (.*?)
* - repeat the previous character or group 0 or more times
+ - repeat the previous character or group 1 or more times

Metacharacters inside square brackets

The part of the pattern enclosed in square brackets is called the character class. Inside brackets, metacharacters lose their special meaning, except for metacharacters belonging to this class. Only 4 characters \ - ] [ need to be escaped. If the "-" character is at the end of the enumeration, it does not require escaping. The pattern can use range metacharacters, but not boundary metacharacters, such as \A, \B, \Z, \z, and the \b metacharacter means the backspace character 'backspace'. Note that ranges such as [a-z] use a UTF-8 sequence, not ASCII.

\ - escape character
^ - exclusion character, but in the case when it comes first, for example [^3] all but three
- - spanning character, for example [az], i.e. all characters from a to z
[ ]- beginning and end of character class description, for example [az]

wildcard metacharacters

\1 - \9 - link to the found group in the template itself and in the replacement template. Counting groups from the left by the opening bracket "("
$1 - $9 - reference to the found group in the replacement pattern
$0 or \0 - the entire search pattern or all groups (9 is not a limit)
\a - Chr(7) - a character with a decimal ASCII code 7 (bell) Plays a beep on output BEL (hex 07)
\cn is the control character that is generated when pressing the key combination Ctrl+n, where n is a character, e.g. \cD corresponds to Ctrl+D. \cA = \001 , \cZ = \032, \cM = \r = \015
\e - Chr(27) - escape character (hex 1B)
\f - Chr(12) page break (hex 0C)
\h- [ \t] - any horizontal space, tab - Chr(9), Chr(32), Chr(160)
\H - [^\h] - any character that is not a space or tab
\K - to the left of \K previous match, i.e. text1 \K text2 , find text2 preceded by text1 .
\n - @LF, Chr(10) - newline character (hex 0A)
\N - [^\n] Any character that is not a newline character (not @LF). Doesn't work in 3.3.6.1
\Q ... \E - any metacharacters between \Q and \E are treated as text. Don't exclude errors: \QD:\Edit\1.txt\E
\r - @CR, Chr(13) - carriage return character (hex 0D)
\R- [\n\f\r\v] Chr(10), Chr(11), Chr(12), Chr(13) any of the line break characters
\t - @TAB, Chr(9) tab character - tab ( hex 09)
\v - [\r\n\f] Chr(10), Chr(11), Chr(12), Chr(13) vertical tab (@CR and @LF and page break)
\V - [^ \v] - any character that is not Chr(10), Chr(11), Chr(12), Chr(13) vertical tab (line break)
\x** - where * is any hexadecimal digit, e.g. \x41 matches latin letter 'A', \x50\x65\x72\x6C - Perl word
\x{**..} - where * is any hexadecimal digit, for example \x{50}\x{65}\x{72}\ x{6C} is a Perl word. Try from \x{01} to \x{7F}, which in decimal means characters from 1 to 127. Or in UTF encoding \x{044F} is equal to the character "i"
\*** - where * is any octal digit. For example, the sequence \120\145\162\154 represents a Perl word (\120 is the octal code of the letter P, \145 is the letter e, \162 is the letter r, \154 is the letter l). Space - \040. Try \001 to \177, which in decimal means characters from 1 to 127

Metacharacters for specifying character groups

\d - [0-9] - any decimal digit
\D - [^0-9] any non-digit
\s - [\f\n\r\t\v ] - empty character: Chr(9), Chr( 10), Chr(12), Chr(13), Chr(32) (page break, tab, carriage return, line feed, and space).
\S - [^\f\n\r\t\v ] - any non-whitespace character
\w - [0-9a-zA-Z_] - any alphanumeric character or underscore (Latin characters only)
\W - [ ^0-9a-zA-Z_] - any non-word character

Character borders

\A - the beginning of the text, does not depend on the flag "(?m)" and therefore can occur only 1 time.
\G - similar to \A , but multiple times if found consecutively from start. \
z - absolute end of text , does not depend on the flag "(?m)" and therefore can only occur once at the end of the line, does not depend on the "(?m)" flag and therefore can only occur once. \b - the beginning or end of a word, i.e. the boundary between characters, one of which satisfies \W, and the other - satisfies \w (only in English texts) \B

- the middle of a word, i.e. the boundary between characters both of which satisfy \W or both of which satisfy \w

Flags modifiers

Placed at the beginning of a regular expression or group.
The state of modifiers is off by default, so you need to enable it to use it.
Usage example: (?i)(Text) or ((?-i)Text), it is allowed to combine (?is)(Text) or ((?imsx)Text)

(?i) - case insensitive. This only works for Latin characters.
(?-i) - cancels the previously included (?i)
(?m) - in multiline text, the symbols ^ and $ mean the beginning and end of the line, respectively, for example ^(Text)\r$, otherwise the beginning and end of the text. LF character - line separator
(?-m) - overrides previously included (?m)
(?s) - dot character (.) additionally includes line break LF ("single line" mode)
(?-s) - overrides the previously included (?s)
(?x) - ignores spaces and tabs in the regular expression, except those in square brackets. The spaces make the regular expression easy to read. Allows at the end of reg. vyp. add a comment after the # symbol
(?-x) - overrides the previously included (?x)
(?J) - allow duplicate names (allows duplicates/double names).
(?U) - invert greedy quantifiers
(?-U) - overrides previously included (?U)

Group Flags

It is allowed to combine (?im-sx:Text) , sx flags are off

(?i:...) - group, case insensitive, for example (?i:Text) . This only works for Latin characters.
(?-i:...) - the group is case-sensitive, for example (?-i:Text)
(?:...) - excludes the group from the found ones, for example (?:Text)
(?>...) - a group not included in the search, but has a super-greedy quantifier property, for example (?>Text)(Text)

These 4 groups have a fixed length, you cannot use * , + , {n, m}
(?=...) in them - group not included in the search, but checkingpattern match on the right , for example (Text)(?=Text)
(?!...) - a group that is not included in the search, but checksthe pattern does not match on the right , for example (Text)(?!Text)
(?<=... ) - a group not included in the search, but checkingpattern matching on the left , for example (?<=Text)(Text) , see also \K
(?<!...) - a group not included in the search, but checking for non-matching pattern left , e.g. (?<!Text)(Text)

(?<name>...)- named link. Calling a named link \k<name> is the same as calling \1 or $1
(?#...) - a group containing a comment, for example (?# is a comment ). Completely ignored by the interpreter

Repeat previous element, applies to characters and groups (quantifiers)

{n} - repeat the previous character n times
{n,} - repeat the previous character n or more times ( {n,}? - preferably the smallest capture)
{n, m} - repeat the previous character n to m times ( {n, m}? - preferably the smallest capture)
* - repeat the previous character 0 or more times. Same as {0,} . The largest grip that will match the rest of the pattern.
+ - repeat the previous character 1 or more times. Same as {1,} . The largest grip that will match the rest of the pattern.
? - the previous character is either present or not present. Same as {0,1}. The second meaning of the symbol ? after the repeat character .*? - greed, see below
*? - repeat the previous character 0 or more times. Will be limited to the smallest grip that will allow the rest of the pattern to match.
+? - repeat the previous character 1 or more times. Will be limited to the smallest grip that will allow the rest of the pattern to match.
?? - preferably the smallest capture, e.g. ([az]??)g for 'gg' returns two empty strings

Jealous or over-greedy quantification

Capture without returning to previous search steps. Captures anything that matches the previous character, without caring about matching the rest of the pattern. The character or range of characters following a supergreedy metacharacter must not be consumed by its range, otherwise such a pattern will never be found and is meaningless. The sole purpose of the overgreedy metacharacter is to speed up capture.

*+ - repeat the previous character 0 or more times.
++ - repeat the previous character 1 or more times.
{n,}+ - repeat the previous character n or more times.

POSIX character classes

Example [[:upper:]]{2} - searches for repeated uppercase letters. Invert the range like this: [[:^digit:]]

[:alnum:] - letters and numbers [0-9A-Za-z] (like \w, but without "_")
[:alpha:] - letters [A -Za-z] (without "_")
[:ascii:] - characters from Chr(0) to Chr(127)
[:blank:] - space and tab character Chr(9) and Chr(32), same as [\t ]
[:cntrl:] - control characters from Chr(0) to Chr(31) and Chr(127)
[:digit:] - decimal digits, same as \d, [0-9]
[:graph: ] - the same as the characters displayed when printing [:print:], but except for the space (from Chr(33) to Chr(126) )
[:lower:] - uppercase letters [az]
[:print:]- printable characters, including space (Chr(32) to Chr(126) )
[:punct:] - printable characters, excluding letters and numbers Chr=(33-47, 58-64, 91- 96, 123-126), those that are neither in [:alnum:] nor in [:cntrl:]
[:space:] are whitespace characters (like \s, but including the VT character: Chr(11) ) from Chr(9) to Chr(13) and Chr(32). Same as [\f\n\r\t\v ]
[:upper:] - uppercase letters [AZ]
[:word:] - word characters, same as \w
[:xdigit:] - hexadecimal digits [0-9A -fa-f]

Conditional subpatterns

(?(if)then) - e.g. (?(?=[az])\d), (?(condition)pattern on_success)
(?(if)then|else) - e.g. (?(?<=\d)a |b) or (?:(?>(?=[^az]*[az])())?(?:(?=\1)aa|(?!\1)1)), (?( condition) pattern_on_success|pattern_on_failure)
(?=[\w]+)| (?R) - recursive call

Эти флаги не действуют в AutoIt3
\p любой символ пунктуации
\l - означает, что следующий символ регулярного выражения преобразуется в нижний регистр.
\u - означает, что следующий символ регулярного выражения преобразуется в верхний регистр.
\L...\Е - означает, что все символы в регулярном выражении между \L и \Е преобразуются в нижний регистр.
\U...\Е - означает, что все символы в регулярном выражении между \U и \Е преобразуются в верхний регистр.
\x - любой шестнадцатеричный символ
\< - начало слова, т. е. граница между символом, удовлетворяющим \W и символом, удовлетворяющим \w
\> - конец слова, т. е. граница между символом, удовлетворяющим \w и символом, удовлетворяющим \W
{,n} - повторить предыдущий символ от 0 до n раз

Примеры конструкций

.* - repetition of any character, which means the whole text
[ ... ] - a single character of the set, for example [aeiou] - any of the lowercase vowels
[^ ... ] - none of the characters of the set, for example [^aeiou] - neither one of the lowercase vowels
[0-9A-Fa-f]{6} - Hexadecimal number, for example FF0000.
[А-яЁё] - Range for Russian letters. Or like this [А-Яа-яЁё]
(\r\n|\r|\n){2,} , replace with \1 - deleting empty lines
(?<![А-яЁё])([А-яЁё] +) \1 , replace with \1 - remove repeated words
[A-ZА-ЯЁЁ]{2,}?[a-za-yaё]+ - will detect files that have errors like "FIND" - not intentional repetition of the capital letters
(.{35,}?[ ])(.*?), replace with '$0' & @CRLF - where @CRLF is a line break character. Check the "Calculate" flag. Carry out a line break at the boundary of the first whitespace after every 35 characters.
(?si)(?:.*?)?(https?:\/\/[\w.:]+\/?(?:[\w\/?&=.~;\-+!*_ #%])*) - find links
[A-Za-z0-9._-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}) - find mailboxes

Links

Tutorials
Regular expressions. J. Friedl. 3rd edition and also html
edlinsoft.blogspot.com - for .NET Framework, explained with examples.
msdn.ru
php.ru , php.net
Control characters (wiki)
ajaxforum.ru
Regular expressions on wiki
regexpstudio.com - Regular expressions for Delphi
docs.notepad-plus-plus.org - Notepad++ official source
pcre .org - Official reference of the PCRE engine (English)

Online testers
regexr.com - here in the Community there are many ready-made regular expressions
for javascript , for php (pagecolumn.com)
cuneytyilmaz.com - for javascript
php-include.ru - on flash player
regex101.com
easyregexp.ru
debuggex.com - shows structurally

Programs for
RegexBuddy test - cool and paid
RegExp - free, AZJIO, PCRE, AutoIt3
Expresso
The Regex Coach

Original text

Contribute a better translation


Search options

Description

Start button

Performs search/replace, etc. with a regular expression

Library

When launched, the program checks the files in the "Library" folder and adds them to the list of libraries. The library contains regular expressions, flags and text processing. The content of the library is displayed on the right side of the window. Clicking on a library element inserts the data into the fields. Two buttons (Add and Delete) are intended for adding (overwriting) and deleting items. By default, the name of the selected item is used, which allows you to overwrite, i.e. update item data. If you need to add a new one, then specify the new name of the item. The library allows you not to lose important regular expressions and always have access to them.

Result Output

The result is displayed in the lower left window. The result depends on the search mode. This can be found-not-found text, or the result of a replacement, or a list of elements, as well as a regular expression error warning in English. language.

Modes

  • Search - returns "Worn" or "Not Found".
  • Replace - returns the text that has been replaced.
    Nearby there are two checkboxes: support for Unescape characters (\r\n\t) and support for groups (\1...\9).
  • Array - returns the entire found elements matching the regular expression.
  • Groups - returns the elements of the regular expression that are in parentheses.
  • Stepping - returns the position, length, and found text of the regular expression.
The flag " With markup " allows you to make the output of the results more visual, with the numbers of the found elements.

Execution speed

There are two fields below the "Start" button. The bottom one shows the execution time of the current regular expression on the current text. The top one is the time of the previous test. This is necessary for speed comparison. If the current test is completed faster than the previous one, then the lower field is highlighted in green, otherwise in red.

Design style

Ini, you can set the color of the window elements and the highlight color of metacharacters in the regular expression field. The style is selected like this: style=style1, while the ini-file should contain the [style1] section with color settings. For example, the ini file contains several predefined styles.

Inserting wildcards

Some combinations can be inserted using the "asterisk" - "*" button, the menu of which can be made independently in Menu.ini.

Story

The history button saves 30 items of the last regular expression usage. Adjusted by parameter maxhistor=30.

Command line

As a tool in PureBasic, you can add with a com line:
-l:PureBasic -nu -i:4 "%TEMPFILE"

Here the keys have the following meaning:
-l:PureBasic - library selection
-nu - do not update (or freeze the processed text so that it does not change when other items are clicked)
-i:4 - select the 4th item, counting from 0. The parameter must be be after the -l key: otherwise it will work when the library is not open
"%TEMPFILE" the path in quotes of the file being opened in the window of the processed text.
This functionality allows you to automatically open RegExpPB with the necessary settings and search or process the source using regular expressions.

Flags

OnTop - short name "On top of all windows"
Do not update - when pasting from the library, the text for processing is not replaced. Suppose you need to process your text with different regular expressions.
There are also 5 included flags that can be included in the regular expression itself using the (?s) method, etc.

Buttons

  • Open - Open a text file for processing.
  • Clear - Clears 4 input fields.
  • Add - Add a sample to the library.
  • Delete - Delete the selected library item.
  • Metacharacters - a choice of ready-made combinations for insertion into a regular expression pattern.
  • Переместить вверх - Перемещает текст из результатов в окно для обработки. Полезно если некий текст надо прогнать через десяток регулярных выражений. После каждого примененния нажимать кнопку чтобы перемещать обработанный текст в результатах наверх для обработки следующим регулярным выражением.
  • Copy - копирует в буфер обмена готовую конструкцию для вставки в код. Для этого в папке "template" есть одноимённые готовые шаблоны, в которых переменные подменяются соотвествующими полями. Чтобы программа была универсальна есть параметр copysel=0, если поменять его на copysel=1, то вместо использования одноименных шаблонов откроется папка с возможностью выбора файла-шаблона, таким образом можно даже для одного режима сделать несколько шаблонов, не говоря уже о разных языках программирования.

Описание ini-файла

[Set] - секция основных параметров
width = 800 - ширина окна
height = 600 - высота окна
fontsize = 11 - размер шрифта
maxhistor = 30 - максимальное число пунктов истории
topmost = 0 - поверх всех окно
lastlib = PureBasic - последняя библиотека, выбираемая при запуске программы
copysel = 0 - Флаг переключения выбора шаблона методом открытия файла
style = style1 - выбор секции стиля

[regexp] - история регулярных выражений
1 = [А-Яа-яЁё]+ - один из элементов истории
2 = (\r\n|\r|\n){2,}

[style1] - секция стиля
gui = f - цвет окна (только Windows)
gadget = f - цвет гаджетов (поле ввода) (только Windows)
gadgetfont = f - цвет шрифта (тексты окна, чекбоксы, надписи) (только Windows)
type = 1 - тип цвета, фон или шрифт (для регулярных выражений)
background = f - цвет фона
default = 0 - цвет шрифта
select_bg = f99 - цвет фона выделенного текста
select_fnt = 0 - цвет шрифта выделенного текста
caret = 0 - цвет курсора
re_Repeat = BFFFBD - цвет повтора {n,m}
re_SqBrackets = BDF7FF - цвет квадратных скобок []
re_RndBrackets = FFBDBD - цвет круглых скобок ()
re_AnyText = E6DDFF - color of any text .*?
re_Meta = FFFFA5 - color of \w metacharacters, etc.
re_Borders = FFDFA5 - border color \A \b etc.
re_ChrH = FFC1F7 - character code color \x01 \x{01}
The color can be set in a simplified way, for example "F" means "FFFFFF", "3F" = "3F3F3F", "F95" = ""FF9955"

Original text

Contribute a better translation


Updates

31.10.2022

Added checkbox "On top of all windows"
Added button "Move up" for processing text multiple times with different regular expressions.

07/11/2022

Fixed replacement with links to groups without groups
Added command line like -l:PureBasic -nu -i:4 "%TEMPFILE"

The "Add" button uses the name of the selected item, and if it is not changed, it offers to overwrite the current one.
Fixed library reading regvar, could not read with empty data.
Added "Do not update"
Added ini-file parameter copysel = 0. Enables template selection in Explorer.
Added PureBasic regular expression library

05/02/2022

Now bit flags when reading/writing to a library (libraries are converted with a bit flag)
Checking if in the group reference replacement field, the group support checkbox is checked.
Added history of regular expressions with saving.
Added hotkey Ctrl+Enter
Added timer color.
Added ini-file parameters: "On top of all windows", the number of history items.
Added save library selection
Added 2 buttons "Add" and "Remove" to populate libraries of regular expressions.
Added "open file" and "drag and drop" buttons to the "text to process" (UTF-8) window.
The color settings are output to the ini file.

04/26/2022

Added regular expression libraries

Plan

Since in Linux there was a double reading of data when clicking on an item, the repeated reading was ignored, but the problem is that you need to click another item to update.
If there is no library, when you click the "Add" button, create a library.
For Linux, fix the functionality of calculating the execution time of a regular expression.
Add a flag to hide 5 flags in the GUI for those who don't use PureBasic and enter the flags in the regex itself. In this case, they need to be reset.

Original text

Contribute a better translation