[erlang-questions] regular expressions on binaries

Paul Mineiro paul-trapexit@REDACTED
Sun Aug 26 03:35:39 CEST 2007


I don't think I do.

For instance: to implement "FOO(a|b)*BAR" I would write:

--------

match_start (<<>>, _) -> nomatch;
match_start (<<"FOO", R/binary>>, pos) -> match_end (R, pos, pos + 3);
match_start (<<_:8, R/binary>>, pos) -> match_start (R, pos + 1).

match_end (<<>>, _, _) -> nomatch;
match_end (<<"BAR", _/binary>>, start, end) -> { match, start, end };
match_end (<<$a:8, R/binary>>, start, end) -> match_end (R, start, end + 1);
match_end (<<$b:8, R/binary>>, start, end) -> match_end (R, start, end + 1).

--------

To me that's seems tedious, likely to be incorrect (especially for more
complicated patterns), and better done by a library.

Is there a better way?

-- p


On Sat, 25 Aug 2007, Ben Munat wrote:

> I think you just want pattern matching on binaries:
>
> http://erlang.org/documentation/doc-5.4.12/doc/programming_examples/bit_syntax.html
>
> b
>
>
> Paul Mineiro wrote:
> > Is there an analog to regexp available that works on binaries?
> >
> > Thanks in advance,
> >
> > -- p
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://www.erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list