[erlang-questions] Erlang re:run regular exp, match problrm

Hynek Vychodil hynek@REDACTED
Sat Oct 30 20:47:04 CEST 2010


I would not thanks on your place. It doesn't do what you want but
works only by accident in this particular example. [^<point]* means
any char except of '<', 'p', 'o', 'i', 'n', 't'. [^<]* would work in
same way in this particular example.

This would work much more generally

re:run("<point x=\"12\" y=\"2\" z=\"4\"/><point x=\"4\"
y=\"2\"z=\"14\"/>", "<point.*?\/>",[global])

but anyway you should use xml parser for xml parsing because xml is
not parseable by regular grammar so regular expression is not proper
tool for do it. You will end up with error prone solution.

On Sat, Oct 30, 2010 at 1:34 PM, Mathias <mathiasstalas@REDACTED> wrote:
> Works like a charm!
>
> Many thanks dlfen!
>
> BR,
> Mathias
>
> On Sat, Oct 30, 2010 at 1:03 PM, dlfen <erlangdlf@REDACTED> wrote:
>
>> try this.
>> re:run("<point x=\"12\" y=\"2\" z=\"4\"/><point x=\"4\" y=\"2\"
>> z=\"14\"/>", "<point[^<point]*\/>",[global]).
>>
>>
>> 在 2010-10-30,下午6:44, Mathias 写道:
>>
>> > Hi there,
>> >
>> > I'm trying to figure out how Erlangs re:run module works.
>> >
>> > When executing this::
>> > 1> re:run("<point x=\"12\" y=\"2\" z=\"4\"/><point x=\"4\" y=\"2\"
>> > z=\"14\"/>", "<point(?:\s|.)*\/>").
>> > {match,[{0,54}]}
>> >
>> > I can see that it gives me a match on the complete XML representation
>> > {match,[{0,54}]}.
>> >
>> > But what I really would like to do is for it to give me a subset of
>> matches
>> > on each entity similar to {match,[{0,26},{27, 26}]}.
>> >
>> > so the output would yield  something like this:
>> > 0-26 gives the first xml entity complete with it's attributes <point
>> x="12"
>> > y="2" z="4"/> and
>> > match 27,26 gives the remaining entity.
>> >
>> > If anyone can spot why my regexp:<point(?:\s|.)*\/> is failing and guide
>> me
>> > in the right direction closer to find the solution it will be greatly
>> > appreciated.
>> >
>> > I know about xmerl but for my trivial case it seems like overkill.
>> >
>> > Thx in advance.
>> >
>> > BR,
>> > Mathias Stalås
>>
>>
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill
your boss.  Be a data hero!
Try GoodData now for free: www.gooddata.com


More information about the erlang-questions mailing list