lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 5/06/2012, at 5:53 PM, Sandeep Ghai wrote:

>>> Hello Everyone,
>>> I just come across the 'preg-match' [1] function of PHP.
>>> Do we have similar function in Lua as well?
> 
>> Is there a significant difference between preg-match and string:match?  Because if not, then..
> 
> Specifically Preg-match is for matching one value or one set of data
> with a given pattern..
> and what I tried with string.match, it matches the pattern and I am
> unable to extract a set of data in the matched pattern.

I'm afraid I'm not quite sure I understand, but does the following do what you mean by "extract a set of data"?

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> =("test a123a test"):match("a(%d+)a")
123