Libraries: RegularExpressions in MQL5 for working with regular expressions

 

RegularExpressions in MQL5 for working with regular expressions:

Regular expressions provide a formal language for quick and flexible processing of texts. Each regular expression is a pattern (mask), for which the regular expression engine tries to find matches in the source text. A pattern consists of one or more character literals, operators, or constructs.

With this library all this features will be available by the means of MQL5. To work with the library, include the Regex.mqh file from the "\MQL5\Include\RegularExpressions\" directory in your code.

Several illustrative examples are provided with the library, which at the same time serve as the test cases. All the samples are taken from the official site of Microsoft Corporation, they vividly demonstrate the main differences from the regular expressions in C# and the features of their use in the MQL5.

Example of working with RegularExpressions for MQL5:

Create a simple graphical interface in the EA to demonstrate these capabilities:



Author: MetaQuotes Software Corp.

 

Found a bug in Tests.mq5 :

2016.05.20 16:08:58.128    Tests (GAZR-6.16,D1)    invalid pointer access in 'RegexFCD.mqh' (87,20)

Full log attached. To reproduce, attach the EA, click on Run for "RegexOptions" then "RegexReplace".

Files:
 

Thanks for all these mt5 files

 

Dear friends,

I have noticed that the library does no longer compile in MetaEditor 5.1643


Could anyone fix it...?

 

@MetaQuotes It would be good is this RegEx could be included in the next version of MT5. Other useful ones will be JSON and XML parsing. For JSON there is SimdJSON that is the fasted library optimized for CPU, and only MT dev team can add such a feature.

 

@MetaQuotes I am hitting conflicts between:

MQL5\Include\RegularExpressions\Regex.mqh

and...

MQL5\Include\Internal\IComparable.mqh
MQL5\Include\Generic\Interfaces\IComparable.mqh

and others.

This matters because other non-regex libraries use the standard MQL5 #includes I have listed and won't compile when used in conjunction.

//#define REGEX_CLASH_INCLUDE
#ifdef REGEX_CLASH_INCLUDE
#include <RegularExpressions\Regex.mqh>
#endif
#include <Generic\HashMap.mqh>
#include <Generic\Internal\DefaultEqualityComparer.mqh>
#include <Generic\Interfaces\IComparable.mqh>
#include <Generic\Internal\CompareFunction.mqh>


void OnStart()
{
   printf("Hello world!");
}

The script will build with the #define commented out. However if you uncomment the #define and try & build the script, you'll see something like the below:

I'd be super grateful for either a workaround or a fix for this please.

MetaQuotes
  • 2023.10.06
  • www.mql5.com
Trader's profile
 
Earthy Stag beetle #:

I'd be super grateful for either a workaround or a fix for this please.

namespace REGULAR
{
  #include <RegularExpressions\Regex.mqh> // delete these strings: #property strict
}

#include <Generic\HashMap.mqh>
#include <Generic\Internal\DefaultEqualityComparer.mqh>
#include <Generic\Interfaces\IComparable.mqh>
#include <Generic\Internal\CompareFunction.mqh>

void OnStart()
{
   printf("Hello world!");
}
 

Thanks fxsaber,

Whilst I was hopeful, I wasn't expecting a reply - especially so quickly.

I presume you mean remove the

#property strict

lines from all the regex header files?

With my best regards, ESB.

 
Earthy Stag beetle #:

I presume you mean remove the

#property strict

lines from all the regex header files?

Right.

 

OK fxsaber,

I have it built - and I learnt something new.

Thank you very much.