This query returns no rows :
SELECT * FROM t WHERE t.s ~ '^(N_|B_).*'
while this one does
SELECT * FROM t WHERE t.s like 'N_%' or t.s like 'B_%';
Why are they not equivalent ?
An underscore character has special meaning in LIKE, for the documentation:
An underscore (_) in pattern stands for (matches) any single character; a percent sign (%) matches any sequence of zero or more characters. (...) To match a literal underscore or percent sign without matching other characters, the respective character in pattern must be preceded by the escape character.
So these queries are equivalent:
SELECT * FROM t WHERE t.s ~ '^(N_|B_).*';
SELECT * FROM t WHERE t.s like 'N\_%' or t.s like 'B\_%';