跳到正文

Regex Library Datapack

作者:GMDU

A datapack library that provides a way to match substrings using regular expressions.

收藏

截图

介绍

中文介绍正在准备中,下面暂时显示原文。

This library requires Moxlib to function.

GMDU Regex Library

by Gears and Moxvallix.

Overview

This library provides a simple regular expression parser, working entirely in mcfunction.

Current Features and Metacharacters

Character | Example | Description
———-|———————-|—————–
[] | [abc] | Character set
[^] | [^abc] | Inverted character set
[x-y] | [A-Z] | Character range
() | (ab) | Group
. | . | Wildcard
\| | (a\|b) | Or
^ | ^abc | Beginning of string
$ | xyz$ | End of string
? | ab? | Zero or one of the preceding token
* | ab* | Zero or more of the preceding token
+ | ab+ | One or more of the preceding token
\ | \+ | Escape following character

If you need help creating your regex pattern, we recommend using RegExr.

Not all features from RegExr are supported in our library, see table above.

Getting Started

This library uses a simple api. The string to match is given in target,
and the regex to match with is set in pattern. These are set in the storage,
regex:api/match

To run the match, run function regex:api/match.

Example

data modify storage regex:api/match target set value "Hello, World!"
data modify storage regex:api/match pattern set value "[A-Za-z]+"
function regex:api/match
{
  success: 1b,
  output: ["H","e","l","l","o"]
}

常见问题

Regex Library Datapack 支持哪些 Minecraft 版本?

Regex Library Datapack 支持 Minecraft Java 版 1.19.4–1.21,共 9 个版本。下载时注意选择和你游戏版本一致的文件。

Regex Library Datapack 怎么安装?

新建世界时在「数据包」里把下载的 .zip 拖进去;已有的存档,把文件放进存档目录下的 datapacks 文件夹,进游戏输入 /reload 即可生效。服务器同样放在世界目录的 datapacks 里。

评论

登录后评论和评分

GMDU 的其他作品

查看全部 →