How can a model prefix match a literal underscore?

An underscore matches one character in LIKE. An explicit ESCAPE character can make the underscore literal.

SQLite example and interpretation

Pattern v!_% requires an underscore after v and allows any suffix. Without an escape, v2 could enter the sample list.

SELECT 'v_2' LIKE 'v!_%' ESCAPE '!', 'v2' LIKE 'v!_%' ESCAPE '!';

Result [[1, 0]]

中文

如何只匹配含下划线的模型前缀?

LIKE 中下划线匹配任一字符,用 ESCAPE 指定转义符可要求匹配字面下划线。

SQLite 示例与适用条件

模式 v!_% 只要求 v 后紧跟下划线,后续任意。没有转义时 v2 也可能混入样本清单。

SELECT 'v_2' LIKE 'v!_%' ESCAPE '!', 'v2' LIKE 'v!_%' ESCAPE '!';

结果 [[1, 0]]

References / 参考来源

Keep reading / 继续阅读