%Topic: Retrieve a number from a string
%Slide: The problem
%Params: 	The file contains 423 lines.
Imagine that we're trying to retrieve the number from a string looking 
like that:

The file contains 423 lines.

(here we suppose that the text is the same in any string, only the number
can be different). 

To construct the expression, select text "423" in the edit field, and press 
"Add parameter" button. A new window should appear with alternatives -- 
the program does not know how we want to interpret 423, so it provides 
some variants. Select "Number" from the list and press "Ok".

%Slide: The result
%LastSlide
%Params: 0:\e:1:\e:-1:0:18:21:0:-1|	The file contains 423 lines.
In the field "Regular expression" we receive "^.*[^0-9]+([0-9]+)", which is a 
correct regular expression for this example. Press button "Copy" and this
expression will be copied into the clipboard.

%Topic: Anchors
%Slide: The problem
%Params: 	There are 423 lines in file number 84.
Now we have a more complicated situation: we still need to retrieve the 
number of lines, however, the string format from the example 1 has changed:

There are 423 lines in file number 84.

So, we have two numbers here - 84 and 423, and the program does not
have enough information to select the proper number of these two. 

If we'd try to receive the result in the same manner as in the previous
example, then after selecting "423" and pressing "Add Parameter" button 
the program would not give us a good alternative: all variants in the list 
are very specific ("element of list '423'" - this variant matches to number 
423 only; Numbers and words of 3 symbols are also not good here, since the
number can be longer or shorter). 

In such situation we need to use more information from the string. 
For example, we could consider that we need the number which is specified 
immediately after "there are" phrase. Let us call such words as "anchors".
These are parameters, which however are not passed to the output of the
expression.

%Slide: STEP 1. Adding the anchor
%Params: 	There are 423 lines in file number 84.
To add an anchor and parse the string, we can select the fisrt two 
words "There are" and press "Add anchor". Then select 
"element of list 'There are'". Now we have a regular expression which 
matches against any string starting with "There are". 

%Slide: STEP 2. Adding the parameter
%Params: 0:\e:7:There are:-1:1:0:9:0:-1|	There are 423 lines in file number 84.
Now we are ready to add the parameter: select "423" and press "Add parameter". 
Here we can select "Number -- a first word after previous parameter" 
and receive the required result.

%Slide: The final result
%LastSlide
%Params: 0:\e:7:There are:-1:1:0:9:0:-1|1:\e:1:\e:-1:0:10:13:4:-1|	There are 423 lines in file number 84.
In the field "Regular expression" we receive the result, which can be 
copied to the clipboard using "Copy" button.

%Topic: Parsing elements of list.
%Slide: The problem and the first step.
%Params: 	door opened 24.09 14:15 --- 14.19 21:04 0x10F920A1
Imagine the following string:
door opened 24.09 14:15 --- 14.19 21:04 0x10F920A1

Here we need to retrieve the event ("door opened" or "door closed"),
date (2nd parameter) and time (3rd parameter) of it. The date/time
and numbers after "---" should be ignored

The problem here is that the event name specified in this string
(door opened) is not the only possible name, and that we need to specify
the other event name (door closed).

The starting order of actions is similar: 

a) Adding event parameter:
Select "door opened" text, press "Add Parameter" and select 
'element of list "door opened"'.

%Slide: STEP 2. Manually editing event parameter
%Params: 0:\e:7:door opened:-1:0:0:11:0:-1|	door opened 24.09 14:15 --- 14.19 21:04 0x10F920A1
Here we need manually edit the parameter, since the source line contains 
only one variant of the event. So we need to add all remaining variants:
select "Value" field of the parameter line in the expression scheme 
part, move cursor to the end of the edit field, then manually type vertical 
bar (|) and "door closed" text.

%Slide: STEP 3. Adding date parameter
%Params: 0:\e:7:door opened\bdoor closed:-1:0:0:11:0:-1|	door opened 24.09 14:15 --- 14.19 21:04 0x10F920A1
All other parameters are straightforward:

Adding date parameter:
Select the date text, press "Add Parameter", and select "Any text of 5 symbols
length --- 1st word after the previous parameter". 

%Slide: STEP 4. Adding time parameter
%Params: 0:\e:7:door opened\bdoor closed:-1:0:0:11:0:-1|1:\e:0:\e:5:0:12:17:4:-1|	door opened 24.09 14:15 --- 14.19 21:04 0x10F920A1
Select the time text, press "Add Parameter", and select
"Any text of 5 symbols length --- 1st word after the previous parameter".

%Slide: The result
%LastSlide
%Params: 0:\e:7:door opened\bdoor closed:-1:0:0:11:0:-1|1:\e:0:\e:5:0:12:17:4:-1|2:\e:0:\e:5:0:18:23:4:-1|	door opened 24.09 14:15 --- 14.19 21:04 0x10F920A1
The resulting expression solves the given problem

%Topic: Parse text with delimiters (fields cannot contain delimiters)
%Slide: The problem
%Params: 	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
A very common task is to parse a text, containing several fields, delimited
with some symbol: with a comma, or semicolon, or some other character.
If this symbol cannot present in any of these fields, then the regular
expression can be built quickly and easy.

Imagine we have a string "aaaa & bbbb ; cccc", it contains three fields,
1st and 2nd fields are separated with '&', and 2nd and 3rd fields - with ';'.
The main condition for the method is that all fields (except for the last)
cannot contain their trailing delimiters.

For example, string "aa;a & bb&b ;cccc&;" would
go (with fields 'aa;a', 'bb&b' and 'cccc&;', since 'aa;a' does not contain
'&' symbol, which terminates the first field, and 'bb&b' does not contain
symbol ';', which terminates the second field). To the contrary, string 
"aa&a & bb;b ; cccc" (with fields 'aa&a', 'bb;b' and 'cccc') would not
go.

%Slide: STEP 1. Selecting the 1st field
%Params: 	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
In order to parse these fields, we need to repeat the following uniform
process:

Select the string aaaa together with all leading/trailing spaces (or
other symbols) between the beginning of the text till the first delimiter.
The delimiter should not included. 

Then press either "Add parameter" (if this field should be extracted from
the string) or "Add anchor" (if we do not need this field, but we need other
fields from the string). 

Let's suppose that we do not need the text in the first field, so press
"Add anchor". The menu would appear, select 
"Word of symbols other than & immediately after the previous parameter". 

%Slide: STEP 2. Skipping 1st delimiter
%Params: 0:\e:6:&:-1:1:0:5:2:-1|	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
Select the delimiter ';' after the first field and press "Add anchor",
then select 'Element of list "&" immediately after previous parameter'.
This delimiter must be parsed and skipped by the regular expression, 
otherwise we'll not be able to parse the remaining fields.

%Slide: STEP 3. Selecting 2nd field
%Params: 0:\e:6:&:-1:1:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
Now we need to select the second string and add the second parameter.

Select the string bb&b together with all leading/trailing spaces between 
the first and the second delimiters. Again, the delimiters should not be 
included.

Let's suppose that we need the text in the second field, so press
"Add parameter" instead of "Add anchor". The menu would appear, select 
"Word of symbols other than ; immediately after previous parameter". 

%Slide: STEP 4. Selecting 2nd delimiter
%Params: 0:\e:6:&:-1:1:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|2:\e:6:;:-1:0:6:12:2:-1|	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
Select the delimiter '&' after the second field, press "Add anchor"
and select 'Element of list ";" immediately after previous parameter'.

%Slide: STEP 5. Selecting 3rd field
%Params: 0:\e:6:&:-1:1:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|2:\e:6:;:-1:0:6:12:2:-1|3:\e:7:;:-1:1:12:13:2:-1|	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
Now we need to add the last parameter.
Let's suppose that we also need this parameter, so press
"Add parameter" again. The menu would appear, but here select 
"Any text immediately after the previous parameter". This would tell
to the regular expression that this field has no trailing delimiters.

%Slide: Final comments
%LastSlide
%Params: 0:\e:6:&:-1:1:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|2:\e:6:;:-1:0:6:12:2:-1|3:\e:7:;:-1:1:12:13:2:-1|4:\e:0:\e:-1:0:13:18:2:-1|	aaaa & bbbb ; cccc	aa;a & bb&b ; cccc&;
Finally, we finished the regular expression.

This method can be easily scaled to any number of parameters and any
number of delimiters. The only condition is that each field terminates
with some symbol, which cannot be a part of that field.

However, this condition may be important, and in the next topic we'll 
show how to construct more complicated conditions.

%Topic: Parse text with delimiters (some of the fields can contain delimiters)
%Slide: The problem
%Params: 	aa&a & bbbb ; cccc & ccc & ccc
Here we'll consider text "aa&a" as the first field, text "bbbb" - as
the second field and all the text after the second field (which terminates
with ';') should be ignored.

Unluckily, this description of the fields does not give us any idea where
the first field ends. So, we need some additional information. 

It's impossible to specifiy in this help all possible variants, so
here we'll suppose that symbol ';' starts a comment, which should be ignored.
And the 1st field terminates with the last '&' symbol outside of the comment.
This is a complicated, but relatively typical case, and it shows some 
ideas how to construct the regular expressions for such cases.

%Slide: STEP 1. Selecting the 1st field (temporary)
%Params: 	aa&a & bbbb ; cccc & ccc & ccc
Select the string which you want to be retrieved from the source
(here it's "aa&a ", again with all whitespace around it). 
Then press “Add Parameter” and make the choice of 
“any text of 5 symbols length immediately after previous parameter”. 

What we need here is that the parameter occupies the proper place, so
that we can add further parameters. So, the particular choice of the 
parameter type is not very important, we'll change it when other fields
will be ready.

%Slide: STEP 2. Selecting the 1st delimiter
%Params: 0:\e:0:\e:5:0:0:5:2:-1|	aa&a & bbbb ; cccc & ccc & ccc
In fact, now we see that the problem is already solved: 

Select the 2nd "&" in this string, press "Add Anchor" and make the choice
of 'Element of list "&" immediately after previous parameter'.

%Slide: STEP 3. Selecting the 2nd field
%Params: 0:\e:0:\e:5:0:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|	aa&a & bbbb ; cccc & ccc & ccc
Select the 2nd field: symbols " bbbb " in this string, 
press "Add Anchor" (we could press "Add Parameter") and make the choice 
of 'Word of symbols, other than ";" immediately after previous parameter'.

%Slide: STEP 4. Correcting the 2nd field type
%Params: 0:\e:0:\e:5:0:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|2:\e:6:;:-1:0:6:12:2:-1|	aa&a & bbbb ; cccc & ccc & ccc
In order to continue, we need to specify, that the 2nd field 
does not contain '&' symbols
also (since we require that the 1st field ends with the last '&' outside
of the comment, then 2nd field should not have any '&'). 

To do this, manually edit "Value" field of the 3rd parameter, and append
'&' symbol to the line.

%Slide: STEP 5. Correcting the 1nd field type
%Params: 0:\e:0:\e:5:0:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|2:\e:6:;&:-1:0:6:12:2:-1|	aa&a & bbbb ; cccc & ccc & ccc
The main idea of the current regular expression is that the 1st parameter
is terminated by the 2nd parameter. So we may just remove the value in the
'length' field of the 1st parameter, and make the 1st parameter just
'Any text'.

%Slide: The result
%LastSlide
%Params: 0:\e:0:\e:-1:0:0:5:2:-1|1:\e:7:&:-1:1:5:6:2:-1|2:\e:6:;&:-1:0:6:12:2:-1|	aa&a & bbbb ; cccc & ccc & ccc	aa & bb ;	aa&bb&cc&;ddd
As you can see, this expression reliably detects the 1st and 2nd
fields in various cases.

%Topic: All text to the first symbol X except last y characters
%Slide: The problem and the first step.
%Params: 	aaaaabbbbbcccccdee12/01/2010
Let us use the following example, string "aaaaaabbbbbcccccdee12/01/2010"

Here we'll use '/' as X and y is equal to 2. So, we need to take
all symbols till '/' except last two symbols (12 in this case).
This text here is aaaaabbbbbcccccdee.

STEP 1. Select the string which you want to be retrieved from the source.
Then press “Add Parameter” and make the choice of “any text of 18 symbols 
length immediately after previous parameter”. 

If we'll remain this parameter as it is, then it will work properly only
when the actual parameter has 18 symbols. However, we will edit it 
later.
%Slide: STEP 2. Selecting anchor
%Params: 0:\e:0:\e:18:1:0:18:2:-1|	aaaaabbbbbcccccdee12/01/2010
Select the anchor, the text that will limit the parameter to be retrived.
We will select the anchor as the text of 2 symbols, limited by '/'.

To do this, select letters 12 and press "Add Anchor". Then, in the list 
of available variants select “word of symbols other than '/' of 2 symbols 
length immediately after previous parameter”.
%Slide: STEP 3. Manually modifying parameter - removing parameter length.
%Params: 0:\e:0:\e:18:0:0:18:2:-1|1:\e:6:/:2:1:18:20:2:-1|	aaaaabbbbbcccccdee12/01/2010
Manually edit the first parameter in the parameters list: 

1) select "Type" cell and change its value to "Not one of set"

2) select "Value" cell and change its value to /

3) select "Length" cell and change its value to 0.

This effectively changes the old type of parameter (any text of the given
length) to the proper type (anything but '/').
%Slide: Final expression
%LastSlide
%Params: 0:\e:6:/:-1:0:0:18:2:-1|1:\e:6:/:2:1:18:20:2:-1|	aaaaabbbbbcccccdee12/01/2010
This is all that we need to do.

%Topic: Take text from position x to position y
%Slide: STEP 1. Selecting anchor
%Params: 	removetakealsoremove
Imagine, we need to take word “take” from string “removetakealsoremove”.
In this example it is situated in positions from 7 to 10. This method
works if the parameter does not start in the beginning of the string.

Select text from the beginning till position 6 – it's the text 
before the 
string being retrieved, which should be removed. Then press "Add Anchor" 
button and select “any text of 6 symbols immediately after the previous
parameter” from the menu.

“Immediately after previous parameter” means that this text should start 
exactly where the previous parameter finishes.
%Slide: STEP 2. Selecting parameter
%Params: 0:\e:0:\e:6:1:0:6:2:-1|	removetakealsoremove
Select the subword “take” and press “Add Parameter”. Then press "Add parameter" button and select “any text of 4 symbols length immediately after previous parameter” from the menu.
%Slide: Final expression
%LastSlide
%Params: 0:\e:0:\e:6:1:0:6:2:-1|1:\e:0:\e:4:0:6:10:2:-1|	removetakealsoremove
This finishes the process - the regular expression below is the one that is needed.
%Topic: Take text from beginnig of text to position y
%Slide: Selecting parameter
%Params: 	takealsoremove
Imagine, we need to take word “take” from string “takealsoremove”.
It is in positions from 1 to 4. This is a special case of the previous task.

In this case there is no symbols to skip before the string start. 
So you need just to omit the first step. 
Just select first 4 letters of the string, press "Add parameter" and 
select the choice “Any text of 5 symbols length immediately after previous 
parameter”.
%Slide: Final expression
%LastSlide
%Params: 0:\e:0:\e:4:0:0:4:2:-1|	takealsoremove
This is all that we need to do.

