[erlang-questions] What is allowed in a pattern in terms of string concatenation?

Daniel Dormont <>
Mon Jun 27 17:52:44 CEST 2011


Suppose I want to test that a certain string String1 ends with a certain other string String2. The best I could come up with is:

case string:substr(lists:reverse(String1), 1, length(String2)) of
	String2 -> ok;
	_ -> not_ok
end

I was thinking there must be a better way, but various attempts along the lines of
	case String1 of
		_ ++ String2 -> ok;

all returned "illegal pattern" errors. I couldn't find a clear explanation online of when exactly ++ is allowed in a pattern and when it's not, so I'm a bit stumped. Is there a better way?

thanks,
Dan

PS I'm aware of regexp and re, but my current environment is a hybrid of R12 and R13B so I'm a bit hesitant to involve either one right now.


More information about the erlang-questions mailing list