gpt4 book ai didi

javascript - 棱镜 : Match language types not starting with dot or : character

转载 作者:行者123 更新时间:2023-11-30 00:07:48 27 4
gpt4 key购买 nike

我正在扩展 Prism使用自定义语言,我想突出显示类型(int、float、bool)。

我想匹配不以点或 : 符号开头的字符串。

我已经尝试过单独使用正则表达式但无法使其工作,所以我可能必须使用 Prism's lookbehind parameter但我无法完成这项工作。

float JsValue.float
float JsValue:float(float testFloat)
int JsValue.int
int JsValue:int(int testInt)

下面的正则表达式捕获了所有不是我想要的内容。

/\b(int|bool|float)\b/

下面的正则表达式(感谢 @anubhava)捕获了我想要的内容,但也捕获了函数名称后的“(”字符。

/(?:^|[^:.])\b(int|bool|float)\b/

谢谢

最佳答案

reference you linked to状态:

lookbehind:
This option mitigates JavaScript’s lack of lookbehind. When set to true, the first capturing group in the regex pattern is discarded when matching this token, so it effectively behaves as if it was lookbehind.

实际上,它是 PCRE \K operator 的一个实现.

所以,使用

/(^|[^:.])\b(int|bool|float)\b/
^^^^^^^^^

(^|[^:.]) 是一个 capturing 组。也设置 lookbehind: true

关于javascript - 棱镜 : Match language types not starting with dot or : character,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37822802/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com