Anatolii Kosorukov
Anatolii Kosorukov

Reputation: 960

Regular Expressions in Erlang. Adding additional match in a result list

I am learning how fetching strings in Erlang works with Regular Expressions. Please explain to me why when I execute regular expression for a list of elements whose values are a sequence from 0 to 255, values greater than 127 fall into the resulting list?

Expected = true,
ValidCharacterList = lists:seq(0, 255),

RegularExpression = "[[:ascii:]]",
{ok, MP} = re:compile(RegularExpression),
{match, _} = re:run(ValidCharacterList, MP),
Result = true,
?assertEqual(Expected, Result).

The result is all elements of that sequence (from 0 to 255).

Full code example.

More code examples.

Upvotes: 1

Views: 123

Answers (1)

José M
José M

Reputation: 3509

POSIX's :ascii: is defined as [\x00-\x7F]. Note, however that Erlang states

There is another character class, ascii, that erroneously matches Latin-1 characters instead of the 0-127 range specified by POSIX. This cannot be fixed without altering the behaviour of other classes, so we recommend matching the range with [\0-\x7f] instead.

Upvotes: 1

Related Questions