Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-09

Regex expressions

9 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Hi,

Is there a simple method of searching a string for a unicode substring and replacing it with the correct character?

At this stage, I'm not really worried about the unicode itself but I have substrings within my string like '\U+00B0' which I'd like to replace with chr(176).

Is there a simple way of doing this?

~Dave

Reply by email

Maik Wojcieszak
to Dave Coventry

Dave,

I've tried some regex units implemented in pascal but they are either not complete or buggy or slow.
The best I've found was PCRE which is kind of a standard in many scripting languages.
I'm not sure if there is a lazarus wrapper but I'm using it with delphi.

http://www.renatomancuso.com/software/dpcre/dpcre.htm

Maik

Show quoted text 20 lines
Hi, Is there a simple method of searching a string for a unicode substring and replacing it with the correct character? At this stage, I'm not really worried about the unicode itself but I have substrings within my string like '\U+00B0' which I'd like to replace with chr(176). Is there a simple way of doing this? ~Dave -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Dave Coventry
to Maik Wojcieszak

Hi Maik,

Maik Wojcieszak wrote 7 lines
I've tried some regex units implemented in pascal but they are either not complete or buggy or slow. The best I've found was PCRE which is kind of a standard in many scripting languages. I'm not sure if there is a lazarus wrapper but I'm using it with delphi. http://www.renatomancuso.com/software/dpcre/dpcre.htm

This is what I've got.

It works, but it's a bit tacky!

  i:=Pos('\U+',mPCharArray);
  while i>0 do
  begin
    subS:=Copy(mPCharArray,i+3,4);
    mainString:=mPCharArray;
    Delete(mainString,i,7);
    Insert(chr(Hex2Dec(subS)),mainString,i);
    mPCharArray:=PChar(mainString);
    i:=Pos('\U+',mPCharArray);
  end;

I was hoping that someone could suggest something a little more elegant!

Reply by email

Marco van de Voort
to Maik Wojcieszak: I've tried some regex units implemented in pascal but they are either not complete or…
Maik Wojcieszak wrote 7 lines
I've tried some regex units implemented in pascal but they are either not complete or buggy or slow. The best I've found was PCRE which is kind of a standard in many scripting languages. I'm not sure if there is a lazarus wrapper but I'm using it with delphi. http://www.renatomancuso.com/software/dpcre/dpcre.htm

The new Delphi XE also has regex units added, but it seems they go for a .NET compatible regex. But I don't the exact differences of MS' implementation with PCRE.

Reply by email

Benito van der Zander

Hi,

I've tried some regex units implemented in pascal but they are either not complete or buggy or slow.

Did you try TRegExpr by Andrey V. Sorokin?

That is the best one.

Benito

Reply by email

Maik Wojcieszak
to Joost van der Sluis: Can you show me the bug-reports? That way it can be fixed. (I suppose you've also used…

Hi,

sorry for beeing too general about that. I was testing this some years ago. I've NEVER tested regex on lazarus.

> Did you try TRegExpr by Andrey V. Sorokin?

I've tested a delphi unit I found on the internet "TRegExpr library from Andrey V. Sorokin" which was
only partially implemented at that time (about 10yrs ago).

The main problem was the lack of some features (positive/negative lookahead) and differences in the syntax compared with perl regex at that point of the development because I am using python regex (perl regex) in some parts of
my sw.

Again, sorry for beeing too general about that.
Maik

Show quoted text 20 lines
On Wed, 2010-09-08 at 08:04 +0200, Maik Wojcieszak wrote: > I've tried some regex units implemented in pascal but they are > either not complete or buggy or slow. > Can you show me the bug-reports? That way it can be fixed. (I suppose you've also used the regex-unit which comes with fpc) Joost -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Mark Morgan Lloyd
to Maik Wojcieszak
Maik Wojcieszak wrote 5 lines
>> Did you try TRegExpr by Andrey V. Sorokin? I've tested a delphi unit I found on the internet "TRegExpr library from Andrey V. Sorokin" which was only partially implemented at that time (about 10yrs ago).

I'm using that on Delphi and to a much lesser extent on Lazarus. It is adequate for my requirements, although to a large extent I'm able to tailor how I solve application-level problems to what underlying facilities I have available.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email