[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pcre regex with capture
- From: Norbert Kiesel <nkiesel@...>
- Date: Thu, 22 Jul 2010 08:25:43 -0700
On Thu, 2010-07-22 at 18:08 +0300, Chris Datfung wrote:
> I've read through the lrexlib doco, but can't seem to get Lua to parse
> a string and capture text. For example in the string:
>
> <myMarker>captureMe</myMarker>
>
> I want to get the string 'captureMe'. Can someone point me to an
> example of how to do this?
>
Not that regular expression matching is the best for parsing XML, but
for this simple task something like this would work:
require 'rex_pcre'
text = rex_pcre.match('<myMarker>captureMe</myMarker>',
[[<[^>]+>(.+)</[^>]+>]])
print(text)
I normally use [[]] around rex_pcre patterns because they (unlike the
Lua patterns) tend to have lots of \ in them you would have to quote in
regular strings.
</nk>