Recent

Author Topic: Regex question  (Read 8916 times)

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Regex question
« Reply #15 on: July 16, 2019, 08:15:09 pm »

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #16 on: July 16, 2019, 09:01:51 pm »
https://github.com/BeRo1985/flre
Uh, that's bad. I never used the github and don't know what should I do with the downloaded zip.
Couldn't find install instructions.
Anyway, thanks.
« Last Edit: July 16, 2019, 09:38:58 pm by justnewbie »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Regex question
« Reply #17 on: July 16, 2019, 10:51:12 pm »
There are two files, FLRE.pas and PUCU.pas, need to be visible to your project. Add their path to your project, or copy them to your folder.

For frequently used units, create a package, add them to the package, and compile the it. Later on, when you need any of these units, add the package to your project.
« Last Edit: July 16, 2019, 10:53:08 pm by engkin »

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #18 on: July 16, 2019, 11:00:35 pm »
There are two files, FLRE.pas and PUCU.pas, need to be visible to your project. Add their path to your project, or copy them to your folder.

For frequently used units, create a package, add them to the package, and compile the it. Later on, when you need any of these units, add the package to your project.
I will give it a shot, thank you for your help!

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #19 on: October 11, 2019, 10:23:32 am »
Hi guys/girls,
I am stuck with a regex problem, cannot figure it out.
This is the text:
Quote
{
   First,//Something text
   Second,
   Small//Something text
   Big
}

I need to get the First, Second, Small and Big (highlighted with Teal).
There are 3 spaces before them, but it can be any not just 3 (from 0 to infinity).
I tried this regex:
(?<=(^\s\s\s))(.*)(?=(,|\/\/|\n))
I doesn't work, see the image. Can anyone help me?




bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Regex question
« Reply #20 on: October 11, 2019, 01:10:31 pm »
(?<=(\n(\s*)))([a-zA-Z]*)(?=([,/\n]))

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #21 on: October 11, 2019, 01:47:02 pm »
(?<=(\n(\s*)))([a-zA-Z]*)(?=([,/\n]))
Thank you, but it gives pattern error:
« Last Edit: October 11, 2019, 01:48:46 pm by justnewbie »

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Regex question
« Reply #22 on: October 11, 2019, 02:01:21 pm »
https://regexr.com gives only a warning  about positive lookbehind.

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #23 on: October 11, 2019, 02:13:11 pm »
https://regexr.com gives only a warning  about positive lookbehind.
I am using the https://regex101.com/, but tried the https://regexr.com and it gives no matches but error:

bytebites

  • Hero Member
  • *****
  • Posts: 633
Re: Regex question
« Reply #24 on: October 11, 2019, 03:01:53 pm »
The "positive lookbehind" feature may not be supported in all browsers.

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #25 on: October 11, 2019, 03:23:26 pm »
The "positive lookbehind" feature may not be supported in all browsers.
I need this thing in my Lazarus program, not in a browser.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Regex question
« Reply #26 on: October 11, 2019, 04:04:41 pm »
Hi guys/girls,
I am stuck with a regex problem, cannot figure it out.
This is the text:
Quote
{
   First,//Something text
   Second,
   Small//Something text
   Big
}

I need to get the First, Second, Small and Big (highlighted with Teal).
There are 3 spaces before them, but it can be any not just 3 (from 0 to infinity).
I tried this regex:
(?<=(^\s\s\s))(.*)(?=(,|\/\/|\n))
I doesn't work, see the image. Can anyone help me?
That looks like a JSON so a JSON parser should work better.

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #27 on: October 11, 2019, 05:19:48 pm »
Thank you, but your advice is not an answer to my question.
I need the proper pattern that can be used in Lazarus.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Regex question
« Reply #28 on: October 11, 2019, 06:42:41 pm »
This quick hack solution does not answer your regex question either, but it does give a correct result.
Code: Pascal  [Select][+][-]
  1. function ParsedOK(aTxt: String; out s1, s2, s3, s4: String): Boolean;
  2. var
  3.   c: SizeInt;
  4.   sl: TStringList;
  5. begin
  6.   Result := False;
  7.   s1 := ''; s2:= ''; s3 := ''; s4 := '';
  8.   aTxt := Trim(aTxt);
  9.   if (Length(aTxt) < 12) or (aTxt[1] <> '{') or (aTxt[Length(aTxt)] <> '}') then
  10.     Exit;
  11.   sl := TStringList.Create;
  12.   try
  13.     sl.Text := aTxt;
  14.     if sl.Count <> 6 then
  15.       Exit;
  16.     c := Pos(',', sl[1]);
  17.     if c = 0 then
  18.       Exit;
  19.     Dec(c);
  20.     s1 := Trim(Copy(sl[1], 1, c));
  21.  
  22.     c := Pos(',', sl[2]);
  23.     if c = 0 then
  24.       Exit;
  25.     Dec(c);
  26.     s2 := Trim(Copy(sl[2], 1, c));
  27.  
  28.     c := Pos('/', sl[3]);
  29.     if c = 0 then
  30.       Exit;
  31.     Dec(c);
  32.     s3 := Trim(Copy(sl[3], 1, c));
  33.  
  34.     s4 := Trim(sl[4]);
  35.     Result := True;
  36.   finally
  37.     sl.Free;
  38.   end;
  39. end;

justnewbie

  • Sr. Member
  • ****
  • Posts: 292
Re: Regex question
« Reply #29 on: October 11, 2019, 06:50:57 pm »
Thank you, but unfortunately it is not good for me. I need REGEX.
(For example: I don't know in advance how many strings will be there, the 4 is just an example. So, I need a general solution, regex can do it.)

 

TinyPortal © 2005-2018