gpt4 book ai didi

dataframe - DataFrames.jl 中 "r"之前的 "..."的用途是什么

转载 作者:行者123 更新时间:2023-12-05 08:36:04 25 4
gpt4 key购买 nike

我注意到人们使用 r".."。它是做什么用的?谢谢

最佳答案

r"..." 是用于定义 regular expression 的 Julia 语法, 并且在需要正则表达式时在整个语言中使用(而不仅仅是在数据框中)。您可以通过在 Julia REPL 的内置帮助中搜索 r"" 来找到有关此语法的更多信息:

help?> r""
@r_str -> Regex

Construct a regex, such as r"^[a-z]*$", without interpolation and unescaping (except
for quotation mark " which still has to be escaped). The regex also accepts one or
more flags, listed after the ending quote, to change its behaviour:

• i enables case-insensitive matching

• m treats the ^ and $ tokens as matching the start and end of individual
lines, as opposed to the whole string.

• s allows the . modifier to match newlines.

• x enables "comment mode": whitespace is enabled except when escaped with \,
and # is treated as starting a comment.

• a disables UCP mode (enables ASCII mode). By default \B, \b, \D, \d, \S, \s,
\W, \w, etc. match based on Unicode character properties. With this option,
these sequences only match ASCII characters.

See Regex if interpolation is needed.

Examples
≡≡≡≡≡≡≡≡≡≡

julia> match(r"a+.*b+.*?d$"ism, "Goodbye,\nOh, angry,\nBad world\n")
RegexMatch("angry,\nBad world")

This regex has the first three flags enabled.

更广泛地说,紧接在引文之前/与引文并列的某个单词或字母的模式称为 string macro (或非标准字符串文字),您甚至可以定义自己的(如在 this 等包中)。 r"..." 语法恰好是内置的,专门用于定义正则表达式对象,这些对象以后可以通过 等函数应用于一个或多个字符串匹配替换

关于dataframe - DataFrames.jl 中 "r"之前的 "..."的用途是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70795299/

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