IsRegExp command

Just starting out? Need help? Post your questions and find answers here.
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

IsRegExp command

Post by marcoagpinto »

Could the team implement a command to check for RegExp or whatever it is called?

Code: Select all

SFX G e ing [^eioy]e 
SFX G 0 ing [eoy]e 
SFX G ie ying ie 
SFX G 0 bing [^aeio][aeiou]b 
For example:

Code: Select all

IsRegExp(string$, pattern$, #Right_to_Left/#Left_to_Right)

Code: Select all

If IsRegExp("party","[^aeio][aeiou]b",#Right_to_Left)=#True blah blah blah

Thank you!
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: IsRegExp command

Post by STARGÅTE »

I do not understand your request.

PB has a Regular Expression library: PureBasic - RegularExpression

It has procedures like:
CreateRegularExpression() - to create a regular expression
IsRegularExpression() - to check whether it is valid.
and MatchRegularExpression() - to match the expression with a string.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: IsRegExp command

Post by marcoagpinto »

STARGÅTE wrote:I do not understand your request.

PB has a Regular Expression library: PureBasic - RegularExpression

It has procedures like:
CreateRegularExpression() - to create a regular expression
IsRegularExpression() - to check whether it is valid.
and MatchRegularExpression() - to match the expression with a string.
Is it built-in or do I have to install the library (and how to install it)?

Thanks!
User avatar
mk-soft
Always Here
Always Here
Posts: 6204
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: IsRegExp command

Post by mk-soft »

Is build-in.

At time only two lib not build in. Engine3d.dll and libmariadb.dll

Don't forget to publish the third-party licenses from the libraries as well.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: IsRegExp command

Post by marcoagpinto »

Thank you my friends,

I will add the licence in the user guide of my application Proofing Tool GUI.
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: IsRegExp command

Post by marcoagpinto »

Not to sound annoying, but why does this produce #True?:

Code: Select all

#RegularExpression=1
a$="score"
b$="[^aeio][aeiou]r"

CreateRegularExpression(#RegularExpression,b$)
match=MatchRegularExpression(#RegularExpression,a$)
FreeRegularExpression(#RegularExpression)
Debug "match:"+Str(match)
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: IsRegExp command

Post by Oma »

marcoagpinto wrote:but why does this produce #True?:
because [^aeio] also matches c,
because [aeiou] matches o,
because r matches r,
And where is the string 'cor' contained :?:
:idea: :wink:
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: IsRegExp command

Post by Bisonte »

To learn and test regex see this site : https://regexr.com/
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: IsRegExp command

Post by marcoagpinto »

marcoagpinto wrote:Not to sound annoying, but why does this produce #True?:

Code: Select all

#RegularExpression=1
a$="score"
b$="[^aeio][aeiou]r"

CreateRegularExpression(#RegularExpression,b$)
match=MatchRegularExpression(#RegularExpression,a$)
FreeRegularExpression(#RegularExpression)
Debug "match:"+Str(match)
Buaaaaaaa

I simply wanted to implement a faster way to decode prefixes and suffixes in my Hunspell tool "Proofing Tool GUI".

But the results aren't the ones it should give.

In my previous message the regex was planned to work like:

"score"
the rules would be:
1) first chr from the right should match "r";
2) second chr from the right should match any of "[aeiou]";
3) third chr from the right SHOULD NOT match any of "[^aeio]" (see the "^").

Can it be done with RegExp commands in PureBasic?

Thank you!
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: IsRegExp command

Post by Oma »

Does b$="[^aeio][aeiou]r$" do what you want?
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: IsRegExp command

Post by #NULL »

marcoagpinto wrote:1) first chr from the right should match "r";
use \b (word boundary) or $ (end of string) after r
marcoagpinto wrote:2) second chr from the right should match any of "[aeiou]";
you have to specify how many of those chars can occur. you can use [...]+ for 1 or more, or use [...]{1} for exactly one char.
marcoagpinto wrote:3) third chr from the right SHOULD NOT match any of "[^aeio]" (see the "^").
i think this should work as is.

<edit>
word boundary is \b, not \w (which is whitespace)
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: IsRegExp command

Post by Marc56us »

word boundary is \b, not \w (which is whitespace)
\w is not withespace

\w : "word character" (letters, digits, _ )

\s : whitespace (space, tab, line break)

(PureBasic uses PCRE)

:wink:
User avatar
marcoagpinto
Addict
Addict
Posts: 1039
Joined: Sun Mar 10, 2013 3:01 pm
Location: Portugal
Contact:

Re: IsRegExp command

Post by marcoagpinto »

Oma wrote:Does b$="[^aeio][aeiou]r$" do what you want?

Yes, it worked but another issue rose.

I have some prefixes in the GB speller which have a dot at the end of the pattern.

For prefixes, I am inverting the word since I believe the regular expressions should be met by checking the dictionary words from left to right, so:

1) SUFFIXES:

Code: Select all

    ; Try to match regular expression - 27/JAN/2019
    CreateRegularExpression(#RegularExpression,b$+"$")
    match=MatchRegularExpression(#RegularExpression,a$)
    FreeRegularExpression(#RegularExpression)
    ProcedureReturn match
2) PREFIXES:

Code: Select all

    ; Try to match regular expression - 27/JAN/2019
    CreateRegularExpression(#RegularExpression,b$+"$")
    match=MatchRegularExpression(#RegularExpression,ReverseString(a$))
    FreeRegularExpression(#RegularExpression)
    ProcedureReturn match

The prefixes codes produces incorrect derivates if the pattern$ has a dot at the end:
PFX F 0 con [^abehilmopru].

Image

I did a DIFF of the two wordlists exported using Tortoise SVN and that is how I found the dot issue.

I have sent an e-mail to some Hunspell related friends asking for their opinion, but can we assume that the dots are a bug in the British .aff file and that I should remove all the dots I can find next to a "]"?

Thank you!

Kind regards,
>Marco A.G.Pinto
----------------
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: IsRegExp command

Post by infratec »

If you want to use regex... you have to know regex :wink:

A dot is a meta character. You have to escape it like \.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: IsRegExp command

Post by Little John »

infratec wrote:If you want to use regex... you have to know regex :wink:
Yes, definitely! It's not possible to seriously handle Regular Expressions by trial and error.
Post Reply