regexp: how to match a null string?

Chris Pressey <>
Fri Mar 28 01:54:53 CET 2003

Hello again.

The regexp behaviour seems very weird to me.
In my mind, "^(.*)$" should match a null string.
It doesn't match any characters, but it's still a valid match.
But because regexp deals only in terms of characters matched -
there's no way to tell!

Erlang (BEAM) emulator version [source] [hipe]

Eshell V5.2.3.3  (abort with ^G)
1> S = "".
2> P = "^(.*)$".
3> regexp:match(S, P).
4> regexp:first_match(S, P).
5> regexp:matches(S, P).
6> regexp:matches("foo", "bar").

Would anyone else be interested in a function like

  regexp:is_match(String, RegExp) -> true | false

?  Or is there a better way to solve this problem?


More information about the erlang-questions mailing list