- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试创建一个包含字符集的正则表达式,该字符集可以包含句点或冒号,但不能以句点结尾。所以我想写一行 "Lorem./: Ipsom dolor sit"
而不是 "Lorem ipsum dolor sit."
这是我当前的正则表达式的样子,但它不起作用,因为如果字符串以句点或冒号结尾,它将匹配:
/(\n{2,})([\wåäöÅÄÖ,()%+\-:.]{2,75}[^.:])(\n{1,})/
我正在寻找一个巨大的、格式错误的纯文本文件中的标题。此文件中的一般模式是,标题前面总是有两个或更多换行符,后面总是有一个或更多换行符。此外,标题有时以 :
结尾,但从不以 .
结尾,但它们有时包含 .
或 :
。此外,它们的长度始终为 2-75 个字符,并且从不以其他标题开头。
如有任何帮助,我们将不胜感激。
编辑:我意识到我的解释很糟糕并且部分错误,因此更新了这篇文章。
最佳答案
一般情况下,如果要匹配不以点结尾的字符串,只需要加上(?<!\.)$
即可。到正则表达式的末尾。
这是一个 negative lookbehind assertion .
在你的特殊情况下,比赛应该在此之后继续,所以我们需要一种不同的方法:
/\n{2,}([ \wåäöÅÄÖ,()%+\-:.]{2,75}(?<!\.))\n+/
将匹配任何一行
\n{2,}
), [ \wåäöÅÄÖ,()%+\-:.]
),.
结尾( (?<!\.)
- ) \n+
)。编辑:
一个新的、扩展的正则表达式,试图合并下面评论中讨论的一些逻辑;格式化为详细的正则表达式:
preg_match_all(
'/(?<=\n\n) # Assert that there are two newlines before the current position
^ # Assert that we\'re at the start of a line
(?![\d -]+$) # Assert that the line consists not solely of digits, spaces and -s
# Assert that the line doesn\'t consist of two Uppercase Words
(?!\s*\p{Lu}\p{L}*\s+\p{Lu}\p{L}*\s*$)
# Match 2-75 of the allowed characters
[ \wåäöÅÄÖ,()%+\-:.]{2,75}
(?<!\.) # Assert that the last one isn\'t a dot
$ # Assert position at the end of a line
(?=\n) # Assert that one newline follows.
/mxu',
$subject, $result, PREG_PATTERN_ORDER);
关于php - 捕获包含 "."或 ":"但不以句点结尾的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4991750/
C 中的字符串或字符数组必须以空字符结尾才能知道它们在哪里结束。为什么相同的规则不适用于其他类型的数组? 例如。计算机如何知道整数数组在哪里结束?整数/浮点数/ double 数组在内存中的表示方式有
我有一堆文件需要查看。这些文件中的所有行都以 ^M (\x0D) 结尾,但最后一行以 ^M^J (\x0D\x0A) 结尾。 显然,Vim 将文件类型确定为 DOS,效果是文件的整个内容是 显示在一行
以下是来自 Why's Poignant Guide to Ruby Chapter 6 的 Ruby 代码片段,他试图在 Ruby 中演示元编程: # Get a metaclass for thi
我有一个编程问题,希望有人能帮我解决。我正在尝试为一项工作任务学习 C 编程,我为自己设定了一个小项目,其中包括读取文件树,其中包括获取有关每个文件的信息的所有子目录。 我遇到的问题是我的程序不会忽略
其他章节请看: react 高效高质量搭建后台系统 系列 尾篇 本篇主要介绍 表单查询 、 表单验证 、 通知 (WebSocket)、 自动构建
我是 FFmepg 的新手,所以如果术语有误,请原谅我。 我想将文本和音频添加到现有的视频文件中。我链接在一起 2 drawText s,然后在不同的过滤器中,我想合并原始源视频的音轨和一些背景音乐。
使用grep我可以使用以下命令搜索单词的开头和结尾 grep -e '\' 这将找到I have a leg.,但找不到play allegro here。 Ripgrep(0.10.0)似乎不支持
$.ajax({ type:'GET', cache: 'false', url:"/foo/", data:{"id": pid}, success:func
我想在我的 iPhone 应用程序中处理旋转手势并在此期间旋转 imageView。在手势结束时,我想将 imageView 旋转到固定位置。所以,即。如果我将 imageView 从 0 弧度旋转到
我知道检测是一种将跟踪代码动态添加到方法中以启用跟踪和调试的技术。 我想知道这是否只是一个“跟踪”选项,硬编码到 CLR 中以仅添加跟踪代码,或者是否能够向方法添加任何代码? 例如,我想检查某个类中每
我正在查看一些专有源代码:使用库的示例程序。 代码是用 C 和 C++ 编写的,使用 make 构建系统。 每个文件都以注释掉的 [] 结尾:/*[]*/ 源文件和 #[]#对于生成文件。这可能是什么
是否可以循环文件中的每一行并检查它是如何结束的(LF/CRLF): using(StreamReader sr = new StreamReader("TestFile.txt")) { st
我从 JSF 网站的编程开始。目前所有文件都以 .xhtml 结尾。当我去http://localhost:8080/myProject/start.jsf一切正常。但是当我将文件从 start.xh
这是一个多站点问题。我有很多网站都带有.htaccess文件,其中包含多行,类似于: rewriterule ^(page-one|page-two|page-three)/?$ /index.php
真的没有简单的映射来跳转到段落的第一行或最后一行吗? { 和 } 是“独占”命令,因此它们会跳转到段落前后的空行如果有的话,但对于段落的实际第一行或最后一行(即,当段落位于缓冲区的顶部或底部时)。 这
我已经尝试了该站点上所有可能的解决方案。我以前使用过改造,过去已经解决了这个问题,但这次我无法解决。我正在使用 StackOverflow API 来获取问题及其详细信息。 API : https:/
我正在做模式匹配如下。但我没有得到正确的输出。请建议正确的代码以获得正确的输出。 代码 #! /usr/bin/perl -w my $subString = "1.3.6.1.2.1.26.2.1.
如何创建 if 语句以检查整数是否以 0 结尾? 例如,我想要一个这样的 if 语句: var test = 107; //107 is an example it'should some unkno
这个问题已经有答案了: javascript how to tell if one number is a multiple of another (6 个回答) 已关闭 3 年前。 每当秒 var
我正在遍历文件树以识别所有 .DYLIB 文件。 #!/bin/bash #script to recursively travel a dir of n levels function traver
我是一名优秀的程序员,十分优秀!