Program Demo_Many_Regex_Tester2; // #sign::23 Max: MAXBOX10: 29/02/2020 15:56:10 //#tech:1:23 perf: threads: 6 192.168.1.66 15:56:10 4.7.1.824.7.1.82 //Jedi Code Library also have wrapper around PCRE. Tried it ? – Arioch 'The {I'm struggling to find a way of using Perl compatible regular expressions in a project. The closest I have got is to download TPerlRegEx from http://www.regexbuddy.com/delphi.html - it's a Delphi wrapper around a C++ PCRE library apparently. Test 4 RegEx Libraries: PerlRegex, Synedit, Systools4 , Synapse https://www.regular-expressions.info/delphi.html } //Picture Chart Box --------------------------------------------------------- // Const UrlPictureLookupInfo = 'https://picsum.photos/seed/%d/%d/%d'; REGEXPRESSION1= '[+-]?([0-9]*[.])?[0-9]+'; //float expression REGEXPRESSION2= '[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)'; REGEXPRESSION3= '^\s*[-+]?[0-9]*\.?[0-9]+\s*$'; REGEXPRESSION4= '-?\d*\.?\d+([eE]\-?\d+)?'; procedure PIC_CloseClick(Sender: TObject; var action: TCloseAction); begin //afrm.Close; action:= cafree; writeln('picchartform close at: '+datetimetostr(now)); end; function RunPictureBox(afrm: TForm; const picnr, asizew, asizeh: integer; const UrlPicture,apath: string; save:boolean): string; var pngStream: TMemoryStream; begin pngStream:= TMemoryStream.Create; try HttpGet(Format(UrlPicture,[picnr, asizew, asizeh]), pngStream); writeln('pic size: '+itoa(pngStream.size)) except //if something wrong try using backup server. writeln('PICexcept: '+ExceptionToString(ExceptionType, ExceptionParam)); end; with TLinearBitmap.Create do try pngStream.Position:= 0; LoadFromStream2(pngStream,'JPG'); //or PNG //afrm:= getForm2(asizew+1,asizeh+1, clblack, // 'picsum.photos: '+'Id: '+inttostr(picnr)); afrm.onclose:= @Pic_CloseClick; paintToCanvas(afrm.canvas, Rect(1,1,Width,Height),false); if save then SaveToFile(apath); result:= apath; finally Dispose; Free; pngStream.Free; end; end; procedure SetTEE_Chart; var frm: TForm; chart3: TChart; begin frm:= getForm2(420,320, clblack, 'TEE_Chart'); //sizeable! chart3:= TChart.create(self) with chart3 do begin parent:= frm; //align:= alClient; setBounds(5,5,335,225) title.caption:= 'FRUIT COMPANY'; AddSeries(TBarSeries.Create(Self)); //series[0].Color:= $FF0000; //series[0].ShowInLegend:=false; series[0].Add(3,'Pears', clRed); series[0].Add(4,'Apples', clGreen); series[0].Add(2,'Citros', clyellow); end; if isInternet then RunPictureBox(frm,20,420,320,UrlPictureLookupInfo,'', False); end; procedure ExtractPhones (const AText : string; APhones : TStrings); begin with TRegExpr.Create do try Expression:= '(\+\d *)?(\((\d+)\) *)?(\d+(-\d*)*)'; if Exec (AText) then REPEAT if Match [3] = '812' then APhones.Add (Match [4]); UNTIL not ExecNext; finally Free; end; end; procedure testPerlRegex; var Rex: TPerlRegex; begin try Rex:= TPerlRegex.Create; try Rex.Subject:= 'This is a teetest of TPerlRegex'; Rex.RegEx:= '\bteetest\b'; //Rex.Regex := // '(?i)href="HTTP://(www\.)?([_a-z\d\-]+(\.[_a-z\d\-]+)?)/?"'; if Rex.Match then WriteLn('Found match: ' + Rex.MatchedText) else WriteLn('Can''t be! No match found!'); //ReadLn; finally Rex.Free; end; except //on E: Exception do Writeln(ExceptiontoString(ExceptionType, ExceptionParam)); end; end; //The RegularExpressions unit defines TRegEx and TMatch as object records. // SynRegExpr unit RegEx Snippet procedure testTRegExprFloat; begin with TRegExpr.Create do try Expression:= REGEXPRESSION1; //'[+-]?([0-9]*[.])?[0-9]+'; if Exec ('3.14159') then writeln(Match[0]+' Match found'); finally Free; end; end; procedure testPerlRegexFloat; var Rex: TPerlRegex; begin try Rex:= TPerlRegex.Create; try Rex.Subject:= '3.141592'; Rex.RegEx:= REGEXPRESSION1; //'[+-]?([0-9]*[.])?[0-9]+'; if Rex.Match then WriteLn('Found float match: ' + Rex.MatchedText) else WriteLn('No Float match found!'); //ReadLn; finally Rex.Free; end; except //on E: Exception do Writeln(ExceptiontoString(ExceptionType, ExceptionParam)); end; end; //C:\Program Files (x86)\maxbox3\source\uPSI_StRegEx.pas //regex of Systools4 add TStNodeHeap = class procedure testTRegExprSystoolsFloat; var REPosition : TMatchPosition; begin with TSTRegEx.Create(self) do try savestrtofile('3.1415926535',Exepath+'pifile.txt') inputfile:= Exepath+'pifile.txt' ; //REGEXPRESSION1; //RegisterMethod('Function CheckString( const S : AnsiString; var REPosition : TMatchPosition): Boolean'); //OutputOptions matchpattern.clear; //matchpattern.add('<[^>]*>'); matchpattern.add(REGEXPRESSION1); CheckString('3.14159', REPosition); outputfile:= exepath+'pifile2.txt' //Expression:= REGEXPRESSION1; //'[+-]?([0-9]*[.])?[0-9]+'; if Execute then writeln(' Systools Float Match found'); finally Free; end; end; procedure STEXpressionPattern; begin with TStExpression.create(self) do begin AddConstant('MPI',3.14159); srlist:= TStringlist.create; GetIdentList(srlist); for it:= 0 to srlist.count-1 do writeln(srlist.strings[it]); srlist.Free; Expression:= '2^10 * ln(8 +MPI)'; writeln(floattoStr(AnalyzeExpression)) free; end; end; function CheckCoefficientBoxesValidInput(InputtedTerm : TEdit) : boolean; var RegularExpressionq : TRegExp; //Match : TMatch; begin {RegularExpressionq:= TRegExp.Create('[-+]?[0-9]*\.?[0-9]+'); Match := RegularExpression.Match(InputtedTerm.Text); if Match.Success then begin ShowMessage('Success.'); end; } end; procedure TgbGoogleParseNaturalListings(ResponseHTML, ResultHostName: string); var Regex: TPerlRegex; begin Regex:= TPerlRegex.Create; RegEx.Regex := '(?i)href="HTTP://(www\.)?([_a-z\d\-]+(\.[_a-z\d\-]+)?)/?"'; RegEx.Subject := ResponseHTML; regex.study if RegEx.Match then repeat //Kind := 1; //ResultHostName := LowerCase(RegEx.SubExpressions[2]); //AddSearchTermAreaResult; until not RegEx.MatchAgain; //http://docwiki.embarcadero.com/CodeExamples/Rio/en/TPerlRegExStudy_(Delphi) with RegEx do begin RegEx := 'Edit1.Text'; Study; Subject := Memo2.Lines.Text; Replacement := 'Edit2.Text'; ReplaceAll; Memo2.Lines.Text := Subject; end; //http://docwiki.embarcadero.com/CodeExamples/Rio/en/TPerlRegExGroups_(Delphi) with regex do begin RegEx := '(Joe|Jack|William|Avarell) (Dalton)? did it'; Subject := 'The sheriff told us that Joe Dalton did it.'; if Match then if GroupCount = 2 then ShowMessage('Wanted: ' + Groups[1] + ' ' + Groups[2]) else ShowMessage('Wanted: ' + Groups[1] + ' (probably Dalton)'); end; end; //http://docwiki.embarcadero.com/CodeExamples/Rio/en/TPerlRegExMatchAgain_(Delphi) procedure TForm1Button1Click(Sender: TObject); var I: Integer; PerlRegEx1: TPerlRegex; begin PerlRegEx1:= TPerlRegex.Create; with PerlRegEx1 do begin RegEx := UTF8toString('Edit1.Text'); Subject := UTF8toString('Edit2.Text'); if Match then begin I := 1; while MatchAgain do I := I + 1; ShowMessage(Format('The regular expression matched the subject string %d times.', [I])); end else ShowMessage('regular expression did''t match the subject string at all.'); end; end; procedure TForm1Button1Click4(Sender: TObject); var PerlRegEx1: TPerlRegex; begin PerlRegEx1:= TPerlRegex.Create; with PerlRegEx1 do begin //State := [preNotBOL]; Subject := 'I like to hang out at maXbox bar'; RegEx := '([A-Za-z]+) bar'; Replacement := '\1 is the name of the bar I like'; if Match then ShowMessage(PerlRegEx1.ComputeReplacement); end; end; procedure TForm1Button1Click5(Sender: TObject); var S : UTF8String; var PerlRegEx1: TPerlRegex; begin // The first example generates an ERegularExpressionsError with message // 'Successful match required.' because the Groups have been cleared when the // Subject is set to empty: //Exception: REQUIRE: There must be a successful match first PerlRegEx1:= TPerlRegex.Create; S := 'The sheriff told us that Joe did it.'; with PerlRegEx1 do begin RegEx := '(Joe|Jack|William|Avarell) did it'; Subject := S; if Match then begin Subject := ''; // Save memory if GroupCount = 1 then S := 'Wanted: ' + Groups[1] else S := 'Nobody wanted'; ShowMessage(S); end; end; end; //http://docwiki.embarcadero.com/CodeExamples/Rio/en/TPerlRegExStoreGroups_(Delphi) procedure TForm1Button2Click(Sender: TObject); var S : UTF8String; PerlRegEx1: TPerlRegex; begin // The second example displays "Wanted: Joe". PerlRegEx1:= TPerlRegex.Create; S := 'The sheriff told us that Joe did it.'; with PerlRegEx1 do begin RegEx := '(Joe|Jack|William|Avarell) did it'; Subject := S; if Match then begin StoreGroups; Subject := ''; // Save memory if GroupCount = 1 then S := 'Wanted: ' + Groups[1] else S := 'Nobody wanted'; ShowMessage(S); end; end; PerlRegEx1.Free; end; procedure CheckRegex(const Input: string); begin //Writeln(Input, ' ', TRegEx.IsMatch(Input, '^\s*[-+]?[0-9]*\.?[0-9]+\s*$')); Writeln(Input+' '+booleanToString(ExecRegExpr(REGEXPRESSION3,Input))) end; function getMatchString(arex, atext: string): string; var RegEx: TPerlRegEx; WordCount: Integer; begin RegEx:= TPerlRegEx.Create; try regEx.Subject:= atext; RegEx.regex:= arex; WordCount := 0; { The Match function performs search and returns...} if RegEx.Match then { If there was a match, enter a loop to extract, count and write all matches and captured substrings. } repeat Inc(WordCount); { Write the complete matched string. } WriteLn('match '+itoa(WordCount)+ ' - '+ RegEx.MatchedText+ { Write the matched substrings. } +' - last debug: '+ RegEx.groups[1]); //RegEx.SubStr(1), result:= result+RegEx.MatchedText; until NOT RegEx.matchagain; //MatchNext < 0; //RegEx.CompileOptions:= RegEx.CompileOptions + [coNoAutoCapture]; //RegEx.Options:= RegEx.Options - [preNoAutoCapture]; RegEx.Options:= RegEx.Options- [preUnGreedy]; finally RegEx.Free; end; WriteLn('Done REX - Press Enter to exit'); end; function IsValidNumber4(s: String): Boolean; var parts: TStringDynArray; begin //parts := SplitStringEx(s, '.'); //function SplitStr(sInput:string; Delimiter:string): TStringArray; parts := SplitStr(s, '.'); case Length(parts) of 1: result := StrToIntDef(s, -1) <> -1; 2: result := (StrToIntDef(parts[0], -1) <> -1) and (StrToIntDef(parts[1], -1) <> -1); else result := FALSE; end; end; var rndpic: integer; iserv: ISWBemServices; iset: ISWbemObjectSet; wmi_dom: string; ENum: IEnumVariant; vObj: OleVariant; Begin //@main // maXcalcF('Sqrt(PI/e^2)') writeln('3. Get Task Process Priority Info:') // iserv:= WMIConnect(isloc,'localhost\root\SecurityCenter2','',''); // Get-WmiObject Win32_process -filter 'name = "ProcessName"' | foreach-object { $_.SetPriority(PriorityLevelID) } iserv:= WMIConnect(WMIStart,'localhost','',''); wmi_dom:= 'Win32_process'; iset:= WMIExecQuery(iserv,'Select * from '+wmi_dom+' WHERE Name="maXbox4.exe"') if WMIRowFindFirst(iset, ENum, vObj) then repeat PrintF('PriorityLevelID of maXbox: %s ',[vObj.Priority]); //vObj.setPriority('128') until not WMIRowFindNext(ENum, vObj); vObj:= unassigned; writeln(GetLastErrorMessage) //SetTEE_Chart; testPerlRegex; //TForm1Button1Click4(self) //TForm1Button1Click5(self) //TForm1Button2Click(self) testPerlRegexFloat; testTRegExprFloat; testTRegExprSystoolsFloat; Writeln('IP Address Test '+booleanToString(ExecRegExpr('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', '192.168.1.044'))) Writeln('Float Number Test '+booleanToString(ExecRegExpr(REGEXPRESSION3, '3.1415926'))) //https://stackoverflow.com/questions/27535200/creating-a-regular-expression-in-delphi-using-tregex CheckRegex('2.334'); CheckRegex('150.2'); CheckRegex('0.23'); CheckRegex('3'); CheckRegex('3..42'); CheckRegex('4-2.3'); CheckRegex('e5.64'); CheckRegex('3 145'); writeln('Is validnumber: '+botostr(IsValidNumber4('3.1415926535'))) (*if isInternet then for it:= 1 to 5 do begin rndpic:= random(30000) sleep(2000) RunPictureBox(frm, rndpic,400,400,UrlPictureLookupInfo, {false=store pic} Exepath+'\images\'+itoa(rndpic)+'.jpg', False); end;*) End. Ref: https://stackoverflow.com/questions/12643009/regular-expression-for-floating-point-numbers#12643073 If you also want to match 123. (a period with no decimal part), then you'll need a slightly longer expression: [+-]?([0-9]+([.][0-9]*)?|[.][0-9]+) //https://www.heise.de/hintergrund/25-Jahre-Delphi-war-ein-Kind-seiner-Zeit-4660219.html?seite=3 https://www.heise.de/forum/heise-online/Kommentare/25-Jahre-Delphi-war-ein-Kind-seiner-Zeit/Ein-Teil-der-Code-Zukunft-ist-mehrsprachig/posting-36135387/show/ Combining three rotors from a set of five, each of the 3 rotor settings with 26 positions, and the plugboard with ten pairs of letters connected, the military Enigma has 158,962,555,217,826,360,000 different settings (nearly 159 quintillion or about 67 bits).[19] Note that (5x4x3)x(26^3) x [26! /(6! x 10! x 2^10)]= 158,962,555,217,826,360,000 ˜ 2^67.1 “Imagine a counterfactual history in which the British had not been able to decipher Enigma messages during the Battle of Britain, the naval war in the Mediterranean, the early years of the Battle of the Atlantic, or in the campaign in the Western Desert. Such a scenario is frightening, as it would be a history that depicts not just a longer, drawn-out war but potentially one with a quite different outcome.” „Stellen Sie sich eine kontrafaktische Geschichte vor, in der die Briten die Enigma-Sprüche während der [Luft-]Schlacht um England, des Seekriegs im Mittelmeer, der frühen Jahre der Atlantik-Schlacht oder im [Afrika-]Feldzug in der [Libyschen] Westlichen Wüste nicht hätten entziffern können. Ein solches Szenario ist beängstigend, denn es wäre eine Geschichte, die nicht nur einen längeren, langwierigen Krieg darstellt, sondern möglicherweise einen Krieg mit einem ganz anderen Ergebnis.“ – Sir Dermot Turing[140] "Hello Siri, open a shell!" Siri: "I don't see an app called "a shell". You could try searching the App Store." public class MainClassWMI { public static void MainWMI() { ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'"); ManagementObjectCollection queryCollection = query.Get(); foreach (ManagementObject mo in queryCollection) { string[] addresses = (string[])mo["IPAddress"]; foreach (string ipaddress in addresses) { Console.WriteLine("IP Address: {0}", ipaddress); } } } } ----code_cleared_checked_clean----