[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [string.gmatch] Getting rid of parentheses?
- From: Jim Whitehead II <jnwhiteh@...>
- Date: Mon, 25 Jul 2011 11:22:55 +0100
On Mon, Jul 25, 2011 at 9:53 AM, Gilles Ganault <gilles.ganault@free.fr> wrote:
> Hello
>
> Google didn't help to figure out why Lua returns found tokens between
> parentheses:
>
> =========
> page = '<span>item1</span><br>(item2)<br>(item3)<br><i>'
>
> for a,b in string.gmatch(page,
> '<span>.-</span><br>(.-)<br>(.-)<br><i>') do
> stuff = a .. b .. "\n"
> print(stuff)
> end
> =========
>
> Here's what the console says:
> =========
> (item2)(item3)
> =========
>
> What's the right way to extract tokens from a string without having
> them displayed with parentheses?
What you are doing is correct, but the strings you are capturing DO
have parenthesis in them. The (.-) pattern says capture everything
(non-greedy) between the left and the right anchor, which are the two
<br> tags. The text contained there are the strings "(item2)" and
"(item3)", as you can clearly see in your definition of 'page'.
If you'd like to remove those parenthesis, since you always expect
them and want them removed, you can do what Rob suggests.
- Jim