Ruby regular expression pattern for UTF8 characters with BOM

Viewed 83

Could you tell me the Ruby regular expression pattern that corresponds to the following Python one.

re.compile(b"\x02\xff\xfe(.*?)\x03\xff\xfe")

This can be used to identify UTF8 characters with BOM (byte order mark).

1 Answers

This yields true:

s = "\u0002\u00ff\u00fe123\u0003\u00ff\u00fe"
p /\u0002\u00ff\u00fe(.*?)\u0003\u00ff\u00fe/.match?(s)

See Ruby proof.

Use \uXXXX notation.

Related