- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我阅读了一些关于匹配“X 除外 Y”的主题,但没有特定于 perl6。我正在尝试匹配和替换除 .和 ”
> my $a = ';# -+$12,678,93.45 "foo" *&';
;# -+$12,678,93.45 "foo" *&
> my $b = $a.subst(/<punct - [\.\"]>/, " ", :g);
===SORRY!===
Unrecognized regex metacharacter - (must be quoted to match literally)
------> my $b = $a.subst(/<punct⏏ - [\.\"]>/, " ", :g);
Unrecognized regex metacharacter (must be quoted to match literally)
------> my $b = $a.subst(/<punct -⏏ [\.\"]>/, " ", :g);
Unable to parse expression in metachar:sym<assert>; couldn't find final '>' (corresponding starter was at line 1)
------> my $b = $a.subst(/<punct - ⏏[\.\"]>/, " ", :g);
> my $b = $a.subst(/<punct-[\.\"]>/, " ", :g);
===SORRY!=== Error while compiling:
Unable to parse expression in metachar:sym<assert>; couldn't find final '>' (corresponding starter was at line 1)
------> my $b = $a.subst(/<punct⏏-[\.\"]>/, " ", :g);
expecting any of:
argument list
term
> my $b = $a.subst(/<punct>-<[\.\"]>/, " ", :g);
===SORRY!===
Unrecognized regex metacharacter - (must be quoted to match literally)
------> my $b = $a.subst(/<punct>⏏-<[\.\"]>/, " ", :g);
Unable to parse regex; couldn't find final '/'
------> my $b = $a.subst(/<punct>-⏏<[\.\"]>/, " ", :g);
> my $b = $a.subst(/<- [\.\"] + punct>/, " ", :g); # $b is blank space, not want I want
> my $b = $a.subst(/<[\W] - [\.\"]>/, " ", :g);
12 678 93.45 "foo"
# this works, but clumsy; I want to
# elegantly say: punctuations except \, and \"
# using predefined class <punct>;
最好的方法是什么?
最佳答案
我认为最自然的解决方案是使用“字符类算术表达式”。这需要使用 +
和 -
任意数量的前缀 Unicode properties或 [...]
字符类:
#;# -+$12,678,93.45 "foo" *&
<+:punct -[."]> # +$12 678 93.45 "foo"
punct
减去
.
和
"
字符的字符类”。
+
和
$
.这些不被视为“标点符号”字符。您可以将它们显式添加到被空格替换的字符集中:
<:punct +[+$] -[."] > # 12 678 93.45 "foo"
+
之前去掉了开头的
:punct
。如果你没有为字符类算术表达式中的第一项写
+
或
-
,那么假定
+
。)
+
和
$
所以你可以用它来代替:
<:punct +:symbol -[."] > # 12 678 93.45 "foo"
:punct
以 :
开头并对应于 Unicode 指定的某些字符属性;或 [...]
枚举特定字符的字符类、反斜杠字符类(例如 \d
)或字符范围(例如 a..z
)。 <...>
断言是一个字符类算术表达式然后开头后的第一个字符
<
必须是四个字符之一:
:
引入 Unicode 属性(例如 <:punct ...>
); [
介绍[...]
字符类(例如 <[abc ...>
); +
或 -
.这后面可以跟空格。然后它必须后跟一个 Unicode 属性( :foo
)或一个 [...]
字符类(例如 <+ :punct ...>
)。 +
开头。或
-
有或没有额外的空格(例如
<:punct - [."] ...>
)。
+
的确切语义是什么和
-
是。我注意到这个令人惊讶的结果:
say $a.subst(/<-[."] +:punct>/, " ", :g); # substitutes ALL characters!?!
<...>
在字符类算术表达式中不被接受。
<ident>
在文档中称为字符类,即使它匹配多个字符的字符串,该字符串与特定模式匹配!)但也包括看起来像是字符类的类喜欢
<punct>
或
<digit>
. (其中许多后者直接对应于 Unicode 属性,因此您只需使用它们即可。)
\d
在字符类算术表达式中使用
+
和
-
算术你必须在
[...]
中列出它字符类。
<punct>
不能使用字符类算术与其他断言结合它可以使用
&
regex conjunction operator 与其他正则表达式结构结合使用:
<punct> & <-[."]> # +$12 678 93.45 "foo"
关于regex - perl6 正则表达式 : match all punctuations except . 和“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57538843/
import urllib2,sys from bs4 import BeautifulSoup,NavigableString from string import punctuation as p
假设这是我们的文本: text = 'After 1992 , the winter and summer Olympics will be held two years apart , with t
这个问题不太可能帮助任何 future 的访问者;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况有关,这些情况并不普遍适用于互联网的全局受众。为了帮助使这个问题更广泛地适用,visit
有人知道从 SQL Server 字段中删除标点符号的好方法吗? 我在想 UPDATE tblMyTable SET FieldName = REPLACE(REPLACE(REPLACE(Field
我感觉标点符号能够访问本地存储数据,而 Java KafkaStreams 库正在重建它并重播更改日志主题中的项目 让我们描述一下我们的场景:我有一个 KafkaStreams 应用程序 A(用 Ja
我有以下接口(interface)实现: package io.khinkali.topology; import org.apache.kafka.streams.processor.*; publ
我很困惑为什么这段代码不能按我想要的方式工作。我正在读取 txt 文件并将每个项目(逗号分隔)打印到新行上。每个项目都用“”包围,并且还包含标点符号。我正在尝试删除这个标点符号。我熟悉 string.
我想检查句子结构的质量。具体来说,我想看看最终用户是否在标点符号后输入空格。我也可以使用 NLP 库或简单的 java 正则表达式解决方案。 例如: “嗨,我叫汤姆·克鲁斯。我喜欢电影” “嗨,我叫汤
我正在寻找诸如之类的句子 Bachelors Degree in early childhood teaching, psychology 我使用斯坦福解析器对文本进行注释。 然后,我迭代每个句子并使
我有一个字符串,我想用它删除所有标点符号。我目前使用: import string translator = str.maketrans('','', string.punctuation) name
print string.punctuation 看起来像这样: !"#$%&'()*+,-./:;?@[\]^_`{|}~ 我想知道我们是否可以在其中添加更多标点符号,例如像这样的中文句号:“。”
我正在使用阿拉伯语文本,我想删除阿拉伯语标点符号示例: s="أهلاً بالعالم في هذه التجربة ! علامات ،الترقيم ؟ ,? لا .اتذكرها" 我希望输
我正在尝试查找句子中的最后一个标点符号或空格字符。 鉴于我有这句话,"Hello! What is your name?" 我希望正则表达式返回 ? 的索引, 但我的正则表达式返回 ! 的索引 我的尝
我正在将数据从 SQL Server 表导出到 .csv 文件,然后我使用 sp_send_email 将数据通过电子邮件发送给该文件。 我的问题是这个值: Cantata Number 212 "P
在流应用程序中的单个任务中,以下两个方法是否独立运行(意味着“process”方法正在处理来自上游源的传入消息,“punctuate”方法也可以根据指定的时间表并行运行,并且WALL_CLOCK_TI
我试图弄清楚如何打开一个文件,将文件中的所有字母变成小写,然后取出所有标点符号。我尝试了一些在网上和书中看到的东西,但我似乎无法弄清楚。 import string def ReadFile(File
根据各种documentation ,要匹配任何标点符号我需要使用“\p{P}”模式 #include #include ... std::string str = "Hello'\"#%&!.:
我正在尝试使用 javascript 的 RegExp 来匹配完整的单词,但是当这些单词以标点符号作为边界时它不起作用。 IE。 (new RegExp("\\b"+RegExp.escape("wh
我正在尝试将旧的 phpBB 论坛数据库移动到新服务器。因此,当我下载 .sql 文件时,我尝试通过 phpMyAdmin 面板将其上传到新数据库。这是我收到的错误: Error There seem
How????are!!!you 我想将字符串拆分为 ['How','are','you']。 我试过以下正则表达式: \?*|\!* 这是行不通的。但是,以下正则表达式有效: \?+|\!+ 有人给
我是一名优秀的程序员,十分优秀!