php - Remove "." (dot) after each word enclosed in pattern
问题描述
I want to remove "." (dot) after each word enclosed in a pattern.
Input :
Lorem *|Ipsum.|* is simply *|dummy.|* text of the *|printing|* and typesetting *|industry.|*.
Output :
Lorem *|Ipsum|* is simply *|dummy|* text of the *|printing|* and typesetting *|industry|*.
解决方案
您可以使用此正则表达式捕获*|sometext.|*
模式文本,并进行适当的分组,
(\*\|[^|]+)\.(\|\*)
并替换为在 group1 中捕获部分并$1$2
从分组中排除的位置,以便将其删除并将部分分组到 group2 中。*|sometext
.
|*
$s = "Lorem *|Ipsum.|* is simply *|dummy.|* text of the *|printing|* and typesetting *|industry.|*.";
echo preg_replace('/(\*\|[^|]+)\.(\|\*)/', '$1$2', $s);
打印以下,去除了内部的点*|text.|*
,
Lorem *|Ipsum|* is simply *|dummy|* text of the *|printing|* and typesetting *|industry|*.
推荐阅读
- html - 为什么在我的 Angular 项目中,当我转到另一条路线时不会替换主页,而只是添加页面底部?
- python - 使用一个字典作为另一个字典的键
- python - Python:如何从另一个在这个类中也是变量的对象声明一个类的对象?
- html - Bootstrap4.1 导航栏垂直项目而不是水平相册示例
- hyperledger-fabric - 在将 Hyperledger composer 部署到多个组织的结构中时,我需要粘贴 org1 和 org2 的 CA 证书
- web-scraping - Scrapy 空 xpath 响应
- laravel - 带有特殊符号 URL 的 HTTP 500 内部服务器错误
- ocr - 如何使用 CreateML 正确训练 OCR 模型?我的不仅不好,而且毫无价值
- javascript - 使用 Jquery 或 Vanilla Js 自定义 CSS 步进器的问题
- gephi - gephi中2个节点之间的所有可能路径