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 Re g Exp program I wrote earlier on AutoIt3


Version 0.5.2 from 2022 Author AZJIO

Site http://azjio.ucoz.ru Discussion:


image

image

image

image

image

az j io.ucoz.ru p urebasic.fr p urebasic.mybb.ru usbtor.ru p uppyrus.org


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


image

Search - returns "Worn" or "Not Found".

image

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).

image

Array - returns the entire found elements matching the regular expression.

image

Groups - returns the elements of the regular expression that are in parentheses.

image

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 ready-made

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 - selection of the 4th item, counting from 0. The parameter must 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 into the window of the processed text.

This functionality allows you to automatically open RegExpPB with the necessary settings and search or process the source with

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


image

image

Open - Open a text file for processing. Clear - Clears 4 input fields.

image

image

Add - Add a sample to the library. Delete - Delete the selected library item.

image

Metacharacters - a choice of ready-made combinations for insertion into a regular expression pattern.

image

Move up - Moves the text from the results to the window for processing. Useful if some text needs to be run through a dozen regular expressions. After each application, press the button to move the processed text in the results up to be processed by the next regular expression.


image

Copy - copies the finished construction to the clipboard for pasting into the code. To do this, in the "template" folder there are ready-made templates of the same name, in which the variables are replaced by the corresponding fields. To make the program universal, there is a copysel=0 parameter, if you change it to copysel=1, then instead of using templates of the same name, a folder will open with the ability to select a template file, so you can

even for one mode, make several templates, not to mention different programming languages.


Description of the ini file


image

[Set] - section of main parameters width = 800 - window width

height = 600 - window height

fontsize = 11 - font size

maxhistor = 30 - maximum number of history items topmost = 0 - top of all window

lastlib = PureBasic - last library selected at program startup

copysel = 0 - Flag to switch template selection by file open method

style = style1 - style section selection


[regexp] - history of regular expressions

1 = [А-Ра-яЁё]+ - one of the elements of the story 2 = (\r\n|\r|\n){2,}


[style1] - style section

gui = f - window color (Windows only)

gadget = f - color of gadgets (input field) (Windows only)

gadgetfont = f - font color (window texts, checkboxes, labels) (Windows only)

type = 1 - color type, background or font (for regular expressions)

background = f - background color default = 0 - font color

select_bg = f99 - background color of selected text select_fnt = 0 - font color of selected text caret = 0 - cursor color

re_Repeat = BFFFBD - repeat color {n,m}

image

re_SqBrackets = BDF7FF - color of square brackets [] re_RndBrackets = FFBDBD - color of round brackets () 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"


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, for example {3,8}

\ is an escape character, accept the 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), e.g. ^text text$

. - any character except line break @LF (default). With flag (?s) - any character

| - "or" character, usually within a group, e.g. (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 template 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 enum, it does not need to be escaped. The pattern can use range metacharacters, but not boundary metacharacters like \A, \B, \Z, \z, and the \b metacharacter means the backspace character 'backspace'. that ranges like [a-z] use a UTF-8 sequence, not ASCII.


\ - escape character

^ is an exception 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 on the left by the opening bracket "("

$1 - $9 - link to found group in replacement template

$0 or \0 - the entire search pattern or all groups (9 is not a limit)

\a - Chr(7) - character with ASCII decimal code 7 (bell). Plays a beep when output. BEL (hex 07)

\cn is a control character that is generated by pressing the key combination Ctrl+n, where n is a character, for example \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 - the preceding match to the left of \K, 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, for example \x41 corresponds to the Latin letter 'A', \x50\x65\x72\x6C is a 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, return carriages, linefeed, 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 the text, does not depend on the "(?m)" flag and therefore can occur only 1 time

\Z - the end of the text, i.e. the boundary between any character and the end of the text or up to the \n character, if it is at the end of the line, does not depend on the "(?m)" flag and therefore can occur only 1 time.

\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), you can combine (?is)(Text) or ((?imsx)Text)


(?i) - do not take into account the case of characters. This only works for Latin characters.

(?-i) - overrides 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 the previously enabled (?m)

(?s) - dot character (.) additionally includes line break LF ("single line" mode)

(?-s) - overrides 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 previously enabled (?x)

(?J) - allow duplicate names (allows duplicates/double names).

(?U) - invert greedy quantifiers

(?-U) - cancels the 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 are fixed length, you cannot use

* , + , {n, m}

(?=...) - a group not included in the search, but checking the match

pattern on the right , for example (Text)(?=Text)

(?!...) - a group not included in the search, but checking for a non-match

pattern on the right , for example (Text)(?!Text)

(?<=...) - a group not included in the search, but checking the match

pattern on the left , e.g. (?<=Text)(Text) , see also \K

(?<!...) - a group not included in the search, but checking for a non-match

pattern on the 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 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, not 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 so: [[:^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:] - characters displayed when printed, including space (Chr(32) to Chr(126) )

[:punct:] - characters displayed when printing, except for letters and numbers Chr=(33-47, 58-64, 91-96, 123-126), those that are neither in [:alnum:], nor in [:cntrl:]

[:space:] - 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:] - capital letters [AZ]

[:word:] - word characters, same as \w

[:xdigit:] - hex 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


These flags have no effect in AutoIt3

\p any punctuation character

\l - means that the next regular expression character is converted to lower case.

\u - means that the next character of the regular expression is converted to upper case.

\L...\E means that all characters in the regular expression between \L and

\E are converted to lower case.

\U...\E means that all characters in the regular expression between \U and \E are converted to uppercase.

\x - any hexadecimal character

\< - the beginning of a word, i.e. the boundary between a character satisfying \W and a character satisfying \w

\> - end of word, i.e. boundary between character matching \w and character matching \W

{,n} - repeat the previous character from 0 to n times


Design examples


.* - repetition of any character, which means the entire text

[ ... ] - a single set character, for example [aeiou] - any of the lowercase vowels

[^ ... ] - none of the characters in the set, for example [^aeiou] - none

from 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 - delete 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 letter

(.{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


textbooks

Regular expressions . J. Friedl. 3rd edition and also html edlinsoft.blo g spot.com - for .NET Framework, explained with examples. msdn.ru

php.ru , php.net _ _

Control characters ( wiki) a j axforum.ru

Regular expressions on the wiki

re g expstudio.com - Regular Expressions for Delphi

docs.note p ad-plus-plus.org - Official source of Notepad++ (English)

p cre.org - Official reference of the PCRE engine


Online testers

re g exr.com - there are many ready-made regular expressions here in the Community

for javascript , for php (pagecolumn.com) cune y tyilmaz.com - for javascript

p hp-include.ru -on flash player re g ex101.com

eas y regexp.ru

debu gg ex.com - shows structurally


Programs for the test Reg exBuddy - cool and paid

Reg Exp - free, AZJIO , PCRE, AutoIt3 Ex p resso

The Reg ex Coach


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.


Updates


31.10.2022


Added checkbox "On top of all windows"

Added "Move Up" button to process text multiple times with different regular expressions.


07/11/2022


Fixed replacement with references 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 field for replacing links to groups, then 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 regular expression libraries.

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. Wherein

need to reset them.

Original text