Upload
tc-ahmet-ayhan-altunoglu
View
223
Download
0
Embed Size (px)
Citation preview
8/13/2019 Syntax of Regular Expressions
1/19
Syntax of Regular Expressions
Introduction
This document is taken from TRegExpr help file, an excellent Regular Expressions library for Delphi,by Andrey V. Sorokin,
Regular Expressions are a widely-used method of specifying patterns of text to search for. Specialmetacharactersallow You to specify, for instance, that a particular string You are looking for occursat the beginning or end of a line, or contains nrecurrences of a certain character.
Regular expressions look ugly for novices, but really they are very simple (well, usually simple ;) ),handily and powerful tool.
I strongly recommend You to play with regular expressions using Mask Helper.
Let's start our learning trip!
Simple matches
Any single character matches itself, unless it is a metacharacterwith a special meaning describedbelow.
A series of characters matches that series of characters in the target string, so the pattern "bluh"would match "bluh'' in the target string. Quite simple, eh ?
You can cause characters that normally function as metacharactersor escape sequencesto beinterpreted literally by 'escaping' them by preceding them with a backslash "\", for instance:metacharacter "^" match beginning of string, but "\^" match character "^", "\\" match "\" and so on.
Examples:
foobar matchs string 'foobar'
\^FooBarPtr matchs '^FooBarPtr'
Escape sequences
Characters may be specified using a escape sequencessyntax much like that used in C and Perl:"\n'' matches a newline, "\t'' a tab, etc. More generally, \xnn, where nn is a string of hexadecimal digits,matches the character whose ASCII value is nn. If You need wide (Unicode) character code, You canuse '\x{nnnn}', where 'nnnn' - one or more hexadecimal digits.
\xnn char with hex code nn
\x{nnnn} char with hex code nnnn (one byte for plain text and two bytes for Unicode)
\t tab (HT/TAB), same as \x09
\n newline (NL), same as \x0a
\r car.return (CR), same as \x0d
\f form feed (FF), same as \x0c
\a alarm (bell) (BEL), same as \x07
8/13/2019 Syntax of Regular Expressions
2/19
\e escape (ESC), same as \x1b
Examples:
foo\x20bar matchs 'foo bar' (note space in the middle)
\tfoobar matchs 'foobar' predefined by tab
Other characters need to escape with \ are brackets () [] and backslash itself \
Character classes
You can specify a character class, by enclosing a list of characters in [], which will match any onecharacter from the list.
If the first character after the "['' is "^'', the class matches any character notin the list.
Examples:
foob[aeiou]r finds strings 'foobar', 'foober' etc. but not 'foobbr', 'foobcr' etc.
foob[^aeiou]r find strings 'foobbr', 'foobcr' etc. but not 'foobar', 'foober' etc.
Within a list, the "-'' character is used to specify a range, so that a-z represents all characters between"a'' and "z'', inclusive.
If You want "-'' itself to be a member of a class, put it at the start or end of the list, or escape it with abackslash. If You want ']' you may place it at the start of list or escape it with a backslash.
Examples:
[-az] matchs 'a', 'z' and '-'
[az-] matchs 'a', 'z' and '-'
[a\-z] matchs 'a', 'z' and '-'
[a-z] matchs all twenty six small characters from 'a' to 'z'
[\n-\x0D] matchs any of #10,#11,#12,#13.
[\d-t] matchs any digit, '-' or 't'.
[]-a] matchs any char from ']'..'a'.
Metacharacters
Metacharacters are special characters which are the essence of Regular Expressions. There aredifferent types of metacharacters, described below.
Metacharacters - line separators
^ start of line
$ end of line
8/13/2019 Syntax of Regular Expressions
3/19
\A start of text
\Z end of text
. any character in line
Examples:
^foobar matchs string 'foobar' only if it's at the beginning of line
foobar$ matchs string 'foobar' only if it's at the end of line
^foobar$ matchs string 'foobar' only if it's the only string in line
foob.r matchs strings like 'foobar', 'foobbr', 'foob1r' and so on
The "^" metacharacter by default is only guaranteed to match at the beginning of the input string/text,
the "$" metacharacter only at the end. Embedded line separators will not be matched by "^'' or "$''.
You may, however, wish to treat a string as a multi-line buffer, such that the "^'' will match after anyline separator within the string, and "$'' will match before any line separator. You can do this byswitching On themodifier /m.
The \A and \Z are just like "^'' and "$'', except that they won't match multiple times when themodifier/mis used, while "^'' and "$'' will match at every internal line separator.
The ".'' metacharacter by default matches any character, but if You switch Off themodifier /s,then '.'won't match embedded line separators.
TRegExpr works with line separators as recommended at www.unicode.org (http://www.unicode.org/unicode/reports/tr18/ ):
"^" is at the beginning of a input string, and, ifmodifier /mis On, also immediately following anyoccurrence of \x0D\x0A or \x0A or \x0D (if You are using Unicode version of TRegExpr, then also\x2028 or \x2029 or \x0B or \x0C or \x85). Note that there is no empty line within the sequence\x0D\x0A.
"$" is at the end of a input string, and, ifmodifier /mis On, also immediately preceding any occurrenceof \x0D\x0A or \x0A or \x0D (if You are using Unicode version of TRegExpr, then also \x2028 or \x2029or \x0B or \x0C or \x85). Note that there is no empty line within the sequence \x0D\x0A.
"." matchs any character, but if You switch Offmodifier /sthen "." doesn't match \x0D\x0A and \x0A
and \x0D (if You are using Unicode version of TRegExpr, then also \x2028 and \x2029 and \x0B and\x0C and \x85).
Note that "^.*$" (an empty line pattern) does not match the empty string within the sequence \x0D\x0A,but matchs the empty string within the sequence \x0A\x0D.
Multiline processing can be easily tuned for Your own purpose with help of TRegExpr propertiesLineSeparators and LinePairedSeparator, You can use only Unix style separators \n or onlyDOS/Windows style \r\n or mix them together (as described above and used by default) or define Yourown line separators!
Metacharacters - predefined classes
\w an alphanumeric character (including "_")
http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn538http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn532http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn5328/13/2019 Syntax of Regular Expressions
4/19
\W a nonalphanumeric
\d a numeric character
\D a non-numeric
\s any space (same as [ \t\n\r\f])
\S a non space
You may use \w, \d and \s within custom character classes.
Examples:
foob\dr matchs strings like 'foob1r', ''foob6r' and so on but not 'foobar', 'foobbr' and so on
foob[\w\s]r matchs strings like 'foobar', 'foob r', 'foobbr' and so on but not 'foob1r', 'foob=r' and so on
TRegExpr uses properties SpaceChars and WordChars to define character classes \w, \W, \s, \S, soYou can easily redefine it.
Metacharacters - word boundaries
\b Match a word boundary
\B Match a non-(word boundary)
A word boundary (\b) is a spot between two characters that has a \w on one side of it and a \W on theother side of it (in either order), counting the imaginary characters off the beginning and end of the
string as matching a \W.
Metacharacters - iterators
Any item of a regular expression may be followed by another type of metacharacters - iterators. Usingthis metacharacters You can specify number of occurrences of previous character, metacharacterorsubexpression.
* zero or more ("greedy"), similar to {0,}
+ one or more ("greedy"), similar to {1,}
? zero or one ("greedy"), similar to {0,1}
{n} exactly n times ("greedy")
{n,} at least n times ("greedy")
{n,m} at least n but not more than m times ("greedy")
*? zero or more ("non-greedy"), similar to {0,}?
+? one or more ("non-greedy"), similar to {1,}?
?? zero or one ("non-greedy"), similar to {0,1}?
8/13/2019 Syntax of Regular Expressions
5/19
{n}? exactly n times ("non-greedy")
{n,}? at least n times ("non-greedy")
{n,m}? at least n but not more than m times ("non-greedy")
So, digits in curly brackets of the form {n,m}, specify the minimum number of times to match the item nand the maximum m. The form {n} is equivalent to {n,n} and matches exactly n times. The form {n,}matches n or more times. There is no limit to the size of n or m, but large numbers will chew up morememory and slow down r.e. execution.
If a curly bracket occurs in any other context, it is treated as a regular character.
Examples:
foob.*r matchs strings like 'foobar', 'foobalkjdflkj9r' and 'foobr'
foob.+r matchs strings like 'foobar', 'foobalkjdflkj9r' but not 'foobr'
foob.?r matchs strings like 'foobar', 'foobbr' and 'foobr' but not 'foobalkj9r'
fooba{2}r matchs the string 'foobaar'
fooba{2,}r matchs strings like 'foobaar', 'foobaaar', 'foobaaaar' etc.
fooba{2,3}r matchs strings like 'foobaar', or 'foobaaar' but not 'foobaaaar'
A little explanation about "greediness". "Greedy" takes as many as possible, "non-greedy" takes asfew as possible. For example, 'b+' and 'b*' applied to string 'abbbbc' return 'bbbb', 'b+?' returns 'b', 'b*?'returns empty string, 'b{2,3}?' returns 'bb', 'b{2,3}' returns 'bbb'.
You can switch all iterators into "non-greedy" mode (see themodifier /g).
Metacharacters - alternatives
You can specify a series of alternativesfor a pattern using "|'' to separate them, so that fee|fie|foe willmatch any of "fee'', "fie'', or "foe'' in the target string (as would f(e|i|o)e). The first alternative includeseverything from the last pattern delimiter ("('', "['', or the beginning of the pattern) up to the first "|'', andthe last alternative contains everything from the last "|'' to the next pattern delimiter. For this reason,it's common practice to include alternatives in parentheses, to minimize confusion about where theystart and end.
Alternatives are tried from left to right, so the first alternative found for which the entire expressionmatches, is the one that is chosen. This means that alternatives are not necessarily greedy. Forexample: when matching foo|foot against "barefoot'', only the "foo'' part will match, as that is the firstalternative tried, and it successfully matches the target string. (This might not seem important, but it isimportant when you are capturing matched text using parentheses.)
Also remember that "|'' is interpreted as a literal within square brackets, so if You write [fee|fie|foe]You're really only matching [feio|].
Examples:
foo(bar|foo) matchs strings 'foobar' or 'foofoo'.
Metacharacters - subexpressions
http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn52whttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn52whttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn52whttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn52w8/13/2019 Syntax of Regular Expressions
6/19
The bracketing construct ( ... ) may also be used for define r.e. subexpressions (after parsing You canfind subexpression positions, lengths and actual values in MatchPos, MatchLen and Match propertiesof TRegExpr, and substitute it in template strings by TRegExpr.Substitute).
Subexpressions are numbered based on the left to right order of their opening parenthesis.
First subexpression has number '1' (whole r.e. match has number '0' - You can substitute it in Replacedirective as '$0' or '$&').
Examples:
(foobar){8,10} matchs strings which contain 8, 9 or 10 instances of the 'foobar'
foob([0-9]|a+)r matchs 'foob0r', 'foob1r' , 'foobar', 'foobaar', 'foobaar' etc.
Metacharacters - backreferences
Metacharacters\1 through \9 are interpreted as backreferences. \ matches previously matchedsubexpression#.
Examples:
(.)\1+ match 'aaaa' and 'cc'.
(.+)\1+ also match 'abab' and '123123'
(['"]?)(\d+)\1 match '"13" (in double quotes), or '4' (in single quotes) or 77 (without quotes) etc
Book Helper Examples:
$B match 'The Gathering' and returns
$B match 'The Gathering' and returns THE
8/13/2019 Syntax of Regular Expressions
7/19
m
Treat string as multiple lines. That is, change "^'' and "$'' from matching at only the very start or end ofthe string to the start or end of any line anywhere within the string, see alsoLine separators.
s
Treat string as single line. That is, change ".'' to match any character whatsoever, even a lineseparators (see alsoLine separators), which it normally would not match.
g
Non standard modifier. Switching it Off You'll switch all following operators into non-greedy mode (bydefault this modifier is On). So, if modifier /g is Off then '+' works as '+?', '*' as '*?' and so on
x
Extend your pattern's legibility by permitting whitespace and comments (see explanation below).
r
Non-standard modifier. If is set then range - additional include russian letter '', - additional include '',and - include all russian symbols.
Sorry for foreign users, but it's set by default. If you want switch if off by default - set false to globalvariable RegExprModifierR.
Themodifier /xitself needs a little more explanation. It tells the TRegExpr to ignore whitespace that isneither backslashed nor within a character class. You can use this to break up your regular expressioninto (slightly) more readable parts. The # character is also treated as a metacharacter introducing a
comment, for example:
((abc) # comment 1| # You can use spaces to format r.e. - TRegExpr ignores it
(efg) # comment 2)
This also means that if you want real whitespace or # characters in the pattern (outside a characterclass, where they are unaffected by /x), that you'll either have to escape them or encode them usingoctal or hex escapes. Taken together, these features go a long way towards making regularexpressions text more readable.
Per l extensions
(?imsxr-imsxr)
You may use it into r.e. for modifying modifiers by the fly. If this construction inlined intosubexpression, then it effects only into this subexpression
Examples:
(?i)Saint-Petersburg matchs 'Saint-petersburg' and 'Saint-Petersburg'
(?i)Saint-(?-i)Petersburg matchs 'Saint-Petersburg' but not 'Saint-petersburg'
http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn53_http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn53_http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn53_http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#dmn53_http://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehphttp://mp3bookhelper.sourceforge.net/help/TagEditing/SyntaxOfRegularExpressions.html#41naehp8/13/2019 Syntax of Regular Expressions
8/19
(?i)(Saint-)?Petersburg matchs 'Saint-petersburg' and 'saint-petersburg'
((?i)Saint-)?Petersburg matchs 'saint-Petersburg', but not 'saint-petersburg'
(?#text)
A comment, the text is ignored. Note that TRegExpr closes the comment as soon as it sees a ")", sothere is no way to put a literal ")" in the comment.
8/13/2019 Syntax of Regular Expressions
9/19
unit Unit1;
interface
usesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls, ExtCtrls, MPlayer;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
Image4: TImage;
Image5: TImage;
Image6: TImage;
Image7: TImage;
Image8: TImage;
Image9: TImage;
Bevel1: TBevel;
Timer1: TTimer;
Timer2: TTimer;
Timer3: TTimer;
MediaPlayer1: TMediaPlayer;
Label1: TLabel;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Image10: TImage;
Image11: TImage;
Image12: TImage;
Image13: TImage;
Image14: TImage;
Image15: TImage;
Timer4: TTimer;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Timer3Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer4Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }procedure reel1;
8/13/2019 Syntax of Regular Expressions
10/19
procedure reel2;
procedure reel3;
procedure checkwin;
procedure clearbar;
end;
varForm1: TForm1;
Reels: Array[1..16] of string =
('bell','cherry','melon','grape','orange','lemon2','cherry1','bell4','bar',
'melon1','cherry','grape','lemon','bell','orange','bar');
Reels1: Array[1..16] of integer = (7,1,2,3,4,5,1,7,6,2,1,3,5,7,4,6);
Reels2: Array[1..16] of integer = (0,0,0,0,0,2,1,4,0,1,0,0,0,0,0,0);
num1,num2,num3 : integer;
number1:integer = 16;
number2:integer = 16;
number3:integer = 16;
time1:integer = 0;
time2:integer = 0;
time3:integer = 0;
timer1length:integer = 0;
timer2length:integer = 0;
timer3length:integer = 0;
holdleft:boolean = false;
holdmid:boolean = false;
holdright:boolean = false;
offerahold:boolean = false;
haswon:boolean = false;
implementation
{$R *.dfm}
procedure TForm1.clearbar;
begin
panel1.Color := clmaroon;
panel1.Font.Color := clolive;
panel2.Color := clmaroon;
panel2.Font.Color := clolive;
panel3.Color := clmaroon;
panel3.Font.Color := clolive;
panel4.Color := clmaroon;
panel4.Font.Color := clolive;
panel5.Color := clmaroon;
panel5.Font.Color := clolive;
panel6.Color := clmaroon;
panel6.Font.Color := clolive;
panel7.Color := clmaroon;
panel7.Font.Color := clolive;panel8.Color := clmaroon;
panel8.Font.Color := clolive;
end;
procedure TForm1.reel1;
var next1,previous1:integer;
begin
Next1 := num1 + 1;
previous1 := num1 - 1;
if next1 = 17 then next1 := 1;
If previous1 = 0 then previous1 :=16;
image1.Picture.LoadFromFile('img\'+Reels[previous1]+'-dark.bmp');
8/13/2019 Syntax of Regular Expressions
11/19
image4.Picture.LoadFromFile('img\'+Reels[num1]+'.bmp');
image7.Picture.LoadFromFile('img\'+Reels[next1]+'-dark.bmp');
end;
procedure TForm1.reel2;
var next2,previous2:integer;begin
Next2 := num2 + 1;
previous2 := num2 - 1;
if next2 = 17 then next2 := 1;
If previous2 = 0 then previous2 :=16;
image2.Picture.LoadFromFile('img\'+Reels[previous2]+'-dark.bmp');
image5.Picture.LoadFromFile('img\'+Reels[num2]+'.bmp');
image8.Picture.LoadFromFile('img\'+Reels[next2]+'-dark.bmp');
end;
procedure TForm1.reel3;
var next3,previous3:integer;
begin
Next3 := num3 + 1;
previous3 := num3 - 1;
if next3 = 17 then next3 := 1;
If previous3 = 0 then previous3 :=16;
image3.Picture.LoadFromFile('img\'+Reels[previous3]+'-dark.bmp');
image6.Picture.LoadFromFile('img\'+Reels[num3]+'.bmp');
image9.Picture.LoadFromFile('img\'+Reels[next3]+'-dark.bmp');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
timerand:integer;
begin
randomize;
timerand := random(151)+100;
timer1length:= timerand;
timer2length:= timerand+100;
timer3length:= timerand+200;
clearbar;
if holdleft then begin holdleft := false; end else timer1.Enabled := true;
if holdmid then begin holdmid := false; end else timer2.Enabled := true;
if holdright then begin holdright := false; end else timer3.Enabled :=
true;
button1.Enabled := false;
mediaplayer1.Close;
mediaplayer1.FileName := 'sfx\reelspin.wav';
mediaplayer1.Open;
mediaplayer1.Play;
button2.Enabled := false;
button3.Enabled := false;button4.Enabled := false;
8/13/2019 Syntax of Regular Expressions
12/19
haswon := false;
offerahold := false;
end;
procedure TForm1.checkwin;
var barnum:integer;
beginif (Reels1[num1]=Reels1[num2]) And (Reels1[num2]=Reels1[num3]) then
begin
mediaplayer1.Close;
mediaplayer1.FileName := 'sfx\win.wav';
mediaplayer1.Open;
mediaplayer1.Play;
haswon:= true;
if Reels1[num1] = 1 then ShowMessage('you won 1!');
if Reels1[num1] = 2 then ShowMessage('you won 2!');
if Reels1[num1] = 3 then ShowMessage('you won 3!');
if Reels1[num1] = 4 then ShowMessage('you won 5!');
if Reels1[num1] = 5 then ShowMessage('you won 10!');
if Reels1[num1] = 6 then ShowMessage('you won 15!');
if Reels1[num1] = 7 then ShowMessage('you won the jackpot 25!');
timer4.Enabled := true;
end
else
timer4.Enabled := true;
barnum := Reels2[num1]+Reels2[num2]+Reels2[num3];
if barnum = 1 then begin
panel1.Color := clred;
panel1.Font.Color := clyellow;
panel2.Color := clmaroon;
panel2.Font.Color := clolive;
panel3.Color := clmaroon;
panel3.Font.Color := clolive;
panel4.Color := clmaroon;
panel4.Font.Color := clolive;
panel5.Color := clmaroon;
panel5.Font.Color := clolive;
panel6.Color := clmaroon;
panel6.Font.Color := clolive;
panel7.Color := clmaroon;
panel7.Font.Color := clolive;
panel8.Color := clmaroon;
panel8.Font.Color := clolive;
offerahold := false;
end
else
if barnum = 2 then beginpanel1.Color := clred;
panel1.Font.Color := clyellow;
panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clmaroon;
panel3.Font.Color := clolive;
panel4.Color := clmaroon;
panel4.Font.Color := clolive;
panel5.Color := clmaroon;
panel5.Font.Color := clolive;
panel6.Color := clmaroon;
panel6.Font.Color := clolive;
panel7.Color := clmaroon;panel7.Font.Color := clolive;
8/13/2019 Syntax of Regular Expressions
13/19
panel8.Color := clmaroon;
panel8.Font.Color := clolive;
offerahold := false;
end
else
if barnum = 3 then begin
panel1.Color := clred;panel1.Font.Color := clyellow;
panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clred;
panel3.Font.Color := clyellow;
panel4.Color := clmaroon;
panel4.Font.Color := clolive;
panel5.Color := clmaroon;
panel5.Font.Color := clolive;
panel6.Color := clmaroon;
panel6.Font.Color := clolive;
panel7.Color := clmaroon;
panel7.Font.Color := clolive;
panel8.Color := clmaroon;
panel8.Font.Color := clolive;
offerahold := false;
end
else
if barnum = 4 then begin
panel1.Color := clred;
panel1.Font.Color := clyellow;
panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clred;
panel3.Font.Color := clyellow;
panel4.Color := clred;
panel4.Font.Color := clyellow;
panel5.Color := clmaroon;
panel5.Font.Color := clolive;
panel6.Color := clmaroon;
panel6.Font.Color := clolive;
panel7.Color := clmaroon;
panel7.Font.Color := clolive;
panel8.Color := clmaroon;
panel8.Font.Color := clolive;
offerahold := true;
end
else
if barnum = 5 then begin
panel1.Color := clred;panel1.Font.Color := clyellow;
panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clred;
panel3.Font.Color := clyellow;
panel4.Color := clred;
panel4.Font.Color := clyellow;
panel5.Color := clred;
panel5.Font.Color := clyellow;
panel6.Color := clmaroon;
panel6.Font.Color := clolive;
panel7.Color := clmaroon;
panel7.Font.Color := clolive;panel8.Color := clmaroon;
8/13/2019 Syntax of Regular Expressions
14/19
panel8.Font.Color := clolive;
offerahold := false;
end
else
if barnum = 6 then begin
panel1.Color := clred;
panel1.Font.Color := clyellow;panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clred;
panel3.Font.Color := clyellow;
panel4.Color := clred;
panel4.Font.Color := clyellow;
panel5.Color := clred;
panel5.Font.Color := clyellow;
panel6.Color := clred;
panel6.Font.Color := clyellow;
panel7.Color := clmaroon;
panel7.Font.Color := clolive;
panel8.Color := clmaroon;
panel8.Font.Color := clolive;
offerahold := false;
end
else
if barnum = 7 then begin
panel1.Color := clred;
panel1.Font.Color := clyellow;
panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clred;
panel3.Font.Color := clyellow;
panel4.Color := clred;
panel4.Font.Color := clyellow;
panel5.Color := clred;
panel5.Font.Color := clyellow;
panel6.Color := clred;
panel6.Font.Color := clyellow;
panel7.Color := clred;
panel7.Font.Color := clyellow;
panel8.Color := clmaroon;
panel8.Font.Color := clolive;
offerahold := false;
end
else
if barnum = 8 then begin
panel1.Color := clred;
panel1.Font.Color := clyellow;panel2.Color := clred;
panel2.Font.Color := clyellow;
panel3.Color := clred;
panel3.Font.Color := clyellow;
panel4.Color := clred;
panel4.Font.Color := clyellow;
panel5.Color := clred;
panel5.Font.Color := clyellow;
panel6.Color := clred;
panel6.Font.Color := clyellow;
panel7.Color := clred;
panel7.Font.Color := clyellow;
panel8.Color := clred;panel8.Font.Color := clyellow;
8/13/2019 Syntax of Regular Expressions
15/19
offerahold := true;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
beginif number1 >= 2 then begin
inc(number1,-1);
num1 := number1;
reel1;
end
else
if number1 = 1 then begin
number1 := 16;
num1 := number1;
reel1;
end;
if time1 = 2 then begin
inc(number2,-1);
num2 := number2;
reel2;
end
else
if number2 = 1 then begin
number2 := 16;
num2 := number2;
reel2;
end;
if time2
8/13/2019 Syntax of Regular Expressions
16/19
if number3 >= 2 then begin
inc(number3,-1);
num3 := number3;
reel3;
end
else
if number3 = 1 then beginnumber3 := 16;
num3 := number3;
reel3;
end;
if time3
8/13/2019 Syntax of Regular Expressions
17/19
image1.Picture.LoadFromFile('img\'+Reels[previous1]+'.bmp');
image4.Picture.LoadFromFile('img\'+Reels[num1]+'.bmp');
image7.Picture.LoadFromFile('img\'+Reels[next1]+'.bmp');
image2.Picture.LoadFromFile('img\'+Reels[previous2]+'.bmp');
image5.Picture.LoadFromFile('img\'+Reels[num2]+'.bmp');
image8.Picture.LoadFromFile('img\'+Reels[next2]+'.bmp');
image3.Picture.LoadFromFile('img\'+Reels[previous3]+'.bmp');
image6.Picture.LoadFromFile('img\'+Reels[num3]+'.bmp');
image9.Picture.LoadFromFile('img\'+Reels[next3]+'.bmp');
timer4.Enabled := false;
button1.Enabled := true;
if offerahold = false then begin // second chance to get a hold ;-)
Randhold := Random(110);
if Randhold >= 90 then offerahold := true;
end;
if haswon = false then if offerahold then begin
// button2.Enabled := true;
// reel three hold disabled for now!
// this is due to the need to check for a win
// which is set up to run after reel three stops!
// so if it isn't even started it can't stop :(
button3.Enabled := true;
button4.Enabled := true;
mediaplayer1.Close;
mediaplayer1.FileName := 'sfx\HOLDOFFER.wav';
mediaplayer1.Open;
mediaplayer1.Play;
button1.SetFocus;
end
else
haswon := false;
end;
procedure TForm1.Button2Click(Sender: TObject);
var next3,previous3:integer;
begin
Next3 := num3 + 1;
previous3 := num3 - 1;
if next3 = 17 then next3 := 1;
If previous3 = 0 then previous3 :=16;
image3.Picture.LoadFromFile('img\'+Reels[previous3]+'-dark.bmp');
image6.Picture.LoadFromFile('img\'+Reels[num3]+'.bmp');
image9.Picture.LoadFromFile('img\'+Reels[next3]+'-dark.bmp');
HoldRight:= true;
Button2.Enabled := false;
mediaplayer1.Close;
mediaplayer1.FileName := 'sfx\HOLD.wav';
mediaplayer1.Open;
mediaplayer1.Play;
end;
procedure TForm1.Button3Click(Sender: TObject);var next2,previous2:integer;
8/13/2019 Syntax of Regular Expressions
18/19
begin
Next2 := num2 + 1;
previous2 := num2 - 1;
if next2 = 17 then next2 := 1;
If previous2 = 0 then previous2 :=16;
image2.Picture.LoadFromFile('img\'+Reels[previous2]+'-dark.bmp');
image5.Picture.LoadFromFile('img\'+Reels[num2]+'.bmp');
image8.Picture.LoadFromFile('img\'+Reels[next2]+'-dark.bmp');
Holdmid:= true;
Button3.Enabled := false;
mediaplayer1.Close;
mediaplayer1.FileName := 'sfx\HOLD.wav';
mediaplayer1.Open;
mediaplayer1.Play;
end;
procedure TForm1.Button4Click(Sender: TObject);
var next1,previous1:integer;
begin
Next1 := num1 + 1;
previous1 := num1 - 1;
if next1 = 17 then next1 := 1;
If previous1 = 0 then previous1 :=16;
image1.Picture.LoadFromFile('img\'+Reels[previous1]+'-dark.bmp');
image4.Picture.LoadFromFile('img\'+Reels[num1]+'.bmp');
image7.Picture.LoadFromFile('img\'+Reels[next1]+'-dark.bmp');
HoldLeft:= true;
Button4.Enabled := false;
mediaplayer1.Close;
mediaplayer1.FileName := 'sfx\HOLD.wav';
mediaplayer1.Open;
mediaplayer1.Play;
end;
end.
8/13/2019 Syntax of Regular Expressions
19/19