Regex problem in MT4

 

Hi,

I have a text:

Blue cars are everywhere.

I'm using this library: https://www.mql5.com/en/code/16566

Also, here is a regex description: https://www.mql5.com/en/articles/2432

The issue:

If I'm using this regex pattern: "Blue", then I get the word "Blue".

But, if I'm using this regex pattern: "^Blue", then I get nothing.

The ^ means: beginning of the line. The "Blue" is at the beginning of the line.

What is the problem with the "^Blue" pattern? Is it a bug?

RegularExpressions in MQL4 for working with regular expressions
RegularExpressions in MQL4 for working with regular expressions
  • www.mql5.com
Note: The library works on the MetaTrader 4 build 1384 and higher. Unzip the archive into the terminal_data_folder. The library codes are located in the: \MQL4\Include\RegularExpressions\ Sample test scripts can be found in the \MQL4\Scripts\RegularExpressionsExamples\ Here is a translation of the RegularExpressions from .Net Framework 4.6.1...
 
linux80s:

Hi,

I have a text:

I'm using this library: https://www.mql5.com/en/code/16566

Also, here is a regex description: https://www.mql5.com/en/articles/2432

The issue:

If I'm using this regex pattern: "Blue", then I get the word "Blue".

But, if I'm using this regex pattern: "^Blue", then I get nothing.

The ^ means: beginning of the line. The "Blue" is at the beginning of the line.

What is the problem with the "^Blue" pattern? Is it a bug?

Normally it should work. I guess it's a wide character issue, the caret ^ isn't recognized as such. There are some samples using a caret in the Tests.mq4 file (Example5_2, Example9_1) you might want to check.
 
lippmaje:
Normally it should work. I guess it's a wide character issue, the caret ^ isn't recognized as such. There are some samples using a caret in the Tests.mq4 file (Example5_2, Example9_1) you might want to check.
Thank you. I found the problem: I had to use the Multiline option.
 
linux80s:
Thank you. I found the problem: I had to use the Multiline option.

But why? How is this a multi-line text:

Blue cars are everywhere.
 
lippmaje:

But why? How is this a multi-line text:

It was just an example, the original text is multi line (I did not think that it does matter, could be misleading, sorry).

As I figured it out the meaning of ^, if Multiline >> beginning of line, if not Multiline >> beginning of string.

 

Again: I have problem with the "^".

Now I need to get the beginning of a string. For example my text is:

Big smile! Big pleasure!

I want to get the 2 "Big". My regex pattern is "^Big", but I get nothing.

(In this case I did not use the Multiline option.)

What is the solution?

 
linux80s:

Again: I have problem with the "^".

Now I need to get the beginning of a string. For example my text is:

I want to get the 2 "Big". My regex pattern is "^Big", but I get nothing.

(In this case I did not use the Multiline option.)

What is the solution?

"Now I need to get the beginning of a string."

You don't need a regular expression to find the beginning of a string. The beginning of a string is at [0]. Or did you mean the beginning of a sentence? If so, what constitutes a sentence to you?

https://www.google.com/search?q=regular+expression+tutorial

 
lippmaje:

"Now I need to get the beginning of a string."

You don't need a regular expression to find the beginning of a string. The beginning of a string is at [0]. Or did you mean the beginning of a sentence? If so, what constitutes a sentence to you?

https://www.google.com/search?q=regular+expression+tutorial

I think my explanation was clear, maybe you misunderstood. I need the "Big" words in my text, but only those which are whole words.

If my text is:

Big smile! Big pleasure! BigBig ocean!

I want to get the first 2 "Big" (green), but no need for "BigBig" (red).

I couldn't get to work the "^" (beginning of the string) and "$" (end of the string), how should I do it?

 
linux80s:

I think my explanation was clear, maybe you misunderstood. I need the "Big" words in my text, but only those which are whole words.

If my text is:

I want to get the first 2 "Big" (green), but no need for "BigBig" (red).

I couldn't get to work the "^" (beginning of the string) and "$" (end of the string), how should I do it?

No it wasn't clear. Wrong demo text, same as before. Why didn't you come up with the right description first place?

You're looking for the word boundary. Take a few minutes time and read a regex tutorial.

 
lippmaje:

No it wasn't clear. Wrong demo text, same as before. Why didn't you come up with the right description first place?

You're looking for the word boundary. Take a few minutes time and read a regex tutorial.

The first demo text was also right, because I couldn't know that the Multiline thing will matter.

I know the word boundary \b, but I want to know how should I use the ^ and $. Can you help?

 
linux80s:

The first demo text was also right, because I couldn't know that the Multiline thing will matter.

I know the word boundary \b, but I want to know how should I use the ^ and $. Can you help?

You know the word boundary, why aren't you using it then ?

I totally agree with lippmaje it was not clear and it's still not. From what you described, you don't need "^" at all. I am even wondering if you need regex at all.

Help with what ?