Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that Lua's libpcre implementation does not support '\d'?

Tags:

regex

pcre

lua

I find that \d is not recognized as [0-9]. See my console output below:

> require "rex_pcre"
> return rex_pcre.new("[0-9]+"):exec("1234")
1       4       table: 0x2141ce0
> return rex_pcre.new("\d+"):exec("1234")
nil

Am I missing something or what?

UPDATE

As Kevin Ballard have correctly answered, string escaping works! e.g.

> return rex_pcre.new("\\d+"):exec("1234")
1       4       table: 0x21427f0
> return rex_pcre.new([[\d+]]):exec("1234")
1       4       table: 0x2142ee0

Thanks Kevin

like image 634
Tzury Bar Yochay Avatar asked Dec 05 '11 04:12

Tzury Bar Yochay


1 Answers

I imagine it's because \d is being interpreted as a string escape by Lua. Try using "\\d+" or [[\d+]] instead. The syntax is explained here.

like image 82
Lily Ballard Avatar answered Sep 27 '22 18:09

Lily Ballard