2.2 Source File Encoding

The Erlang source file encoding is selected by a comment in one of the first two lines of the source file. The first string that matches the regular expression coding\s[:=]\s([-a-zA-Z0-9])+ selects the encoding. If the matching string is an invalid encoding, it is ignored. The valid encodings are Latin-1 and UTF-8, where the case of the characters can be chosen freely.

The following example selects UTF-8 as default encoding:

1. %% coding: utf-8

Two more examples, both selecting Latin-1 as default encoding:

1. %% For this file we have chosen encoding = Latin-1
1. %% -*- coding: latin-1 -*-

The default encoding for Erlang source files is changed from Latin-1 to UTF-8 since Erlang/OTP 17.0.