KScript 文档
ZH

类型与验证

接受这些类型的内置函数

处理模式的字符串方法接受正则表达式字面量(连同其标志)或包含模式的文本。无论哪种方式,耗时超过一秒的匹配都会以错误中止:

<let name="title" value="'Hello  World, hello'" />
<echo>{ $title->matches(/^hello/i) } { $title->find_all(/hello/i) }</echo>
<echo>{ $title->replace(/\s+/, ' ') } { 'tea, coffee ,milk'->split(/\s*,\s*/) }</echo>
<echo>{ $title->replace(/(?&lt;w>world)/i, '[${w}]') }</echo>
$title = 'Hello  World, hello'
echo "{ $title->matches(/^hello/i) } { $title->find_all(/hello/i) }"
echo "{ $title->replace(/\s+/, ' ') } { 'tea, coffee ,milk'->split(/\s*,\s*/) }"
echo "{ $title->replace(/(?<w>world)/i, '[${w}]') }"

->replace()和->split()仍然接受纯文本,按原样匹配。存储文件夹的list方法接受通配符(如'*.json')或针对每个名称匹配的正则表达式(如/^notes\/.*\.md$/)。

在 KScript.Terminal 中,input 读取新的类型:type="email"、handle 或 uuid 在回答不符合要求时会附带原因再次询问,type="password" 会隐藏输入的内容并将答案作为密码保存。