lua-users home
lua-l archive

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


On Monday, April 29, 2013 03:10:53 PM Dirk Laurie wrote:
> Besides `sed`, there's also Python:
> >>> import re
> >>> re.subn(re.compile("a*"),"ITEM",";a;")
> 
> ('ITEM;ITEM;ITEM', 3)
> 
> Many Lua users come from a background in which they know sed and Python.
> That tends to influence what things they find intuitive.

However, Perl and PHP do the same thing as Lua.

$ perl -e '$s=";a;";$s=~s/a*/ITEM/g;print "$s\n";' 
ITEM;ITEMITEM;ITEM
$ php -r '$s=preg_replace("/a*/","ITEM",";a;");print("$s\n");'
ITEM;ITEMITEM;ITEM
$ php -r '$s=ereg_replace("a*","ITEM",";a;");print("$s\n");'
ITEM;ITEMITEM;ITEM

And LPEG...
> re = require"re"
> print(re.gsub(";a;","'a'*","ITEM"))
/home/tnharris/share/lua/5.2/re.lua:230: loop body may accept empty string

-- 
tom <telliamed@whoopdedo.org>