www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - ctRegex not matching correctly at word boundaries

reply Ivo <ivo asdasdl.com> writes:
First of all, I'm not an expert about regular expression syntax, 
however I believe there might be some strange bug when using 
ctRegex.

Consider the following code:

void main() {
         import std.regex: ctRegex, matchFirst;
	auto expression = ctRegex!("\bis\b");
	auto match = matchFirst("This island is beautiful", expression);
	if(match.empty) writeln("no match");
	else writeln("match");
}
when I compile and run I get the output "no match".

Looking online I found this website 
https://www.regular-expressions.info/wordboundaries.html where 
they explain that the above regex should match that string.

So I don't understand what's wrong with my code.

P.S.: using regex instead of ctRegex doesn't solve the problem.
Jul 08 2018
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 08/07/2018 10:37 PM, Ivo wrote:
 First of all, I'm not an expert about regular expression syntax, however 
 I believe there might be some strange bug when using ctRegex.
 
 Consider the following code:
 
 void main() {
          import std.regex: ctRegex, matchFirst;
      auto expression = ctRegex!("\bis\b");
auto expression = ctRegex!(`\bis\b`); \b is bell escape code as per ASCII
Jul 08 2018
parent Ivo <ivo asdasdl.com> writes:
On Sunday, 8 July 2018 at 10:58:24 UTC, rikki cattermole wrote:
 On 08/07/2018 10:37 PM, Ivo wrote:
 First of all, I'm not an expert about regular expression 
 syntax, however I believe there might be some strange bug when 
 using ctRegex.
 
 Consider the following code:
 
 void main() {
          import std.regex: ctRegex, matchFirst;
      auto expression = ctRegex!("\bis\b");
auto expression = ctRegex!(`\bis\b`); \b is bell escape code as per ASCII
Thanks a lot. I forgot to put an r before the quotes. My silly mistake.
Jul 08 2018