CyberTre

Regular Expressions Demo 1

Oct 16th, 2021 (edited)
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.82 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     ListBox1: TListBox;
  12.     ListBox2: TListBox;
  13.     procedure FormShow(Sender: TObject);
  14.   private
  15.     procedure ExtrairMedidas;
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. uses
  27.   System.RegularExpressions;
  28.  
  29. {$R *.dfm}
  30.  
  31. procedure TForm1.FormShow(Sender: TObject);
  32. begin
  33.   ExtrairMedidas;
  34. end;
  35.  
  36. procedure TForm1.ExtrairMedidas;
  37. var
  38.   I: Integer;
  39.   R: TRegEx;
  40.   M: TMatch;
  41. begin
  42.   for I := 0 to Pred(ListBox1.Count) do begin
  43.     R := TRegEx.Create('\d+\s?[X,x]\s?\d+',[roIgnoreCase]);
  44.     M := R.Match(ListBox1.Items[I]);
  45.     if M.Success then
  46.       ListBox2.Items.Add(M.Value);
  47.   end;
  48.  
  49. end;
  50.  
  51. end.
  52.  
  53. //=====================================================================================
  54.  
  55. object Form1: TForm1
  56.   Left = 0
  57.   Top = 0
  58.   Caption = 'Form1'
  59.   ClientHeight = 163
  60.   ClientWidth = 503
  61.   Color = clBtnFace
  62.   Font.Charset = DEFAULT_CHARSET
  63.   Font.Color = clWindowText
  64.   Font.Height = -11
  65.   Font.Name = 'Tahoma'
  66.   Font.Style = []
  67.   OldCreateOrder = False
  68.   OnShow = FormShow
  69.   PixelsPerInch = 96
  70.   TextHeight = 13
  71.   object ListBox1: TListBox
  72.     Left = 8
  73.     Top = 32
  74.     Width = 249
  75.     Height = 97
  76.     ItemHeight = 13
  77.     Items.Strings = (
  78.       'KIT ENGENHARIA 1200 X 1200 8 MM'
  79.       'KIT BOX CANTO ALUMASA 1000X1900'
  80.       'KIT ENG WD J2 250 X 120'
  81.       'KIT PORTA 1200 X 2400 8MM 2 FOLHAS'
  82.       'KIT RETRATIL 2F 1000X2400')
  83.     TabOrder = 0
  84.   end
  85.   object ListBox2: TListBox
  86.     Left = 280
  87.     Top = 32
  88.     Width = 209
  89.     Height = 97
  90.     ItemHeight = 13
  91.     TabOrder = 1
  92.   end
  93. end
  94.  
  95.  
Add Comment
Please, Sign In to add comment