regex - End a regular expression pattern with a string
问题描述
all. I have spent some time now to learn regular expression, but eventually there is a problem I cannot solve properly.
Lets assume the following 'string' (html-extract):
"{'2018-05-02', '2018-01-05', r, '2018-07-01', '2017-07-02', '2016-07-31' random_text XYCCC Letters and 55565798 ]}"
My intention is, to extract all values from '2018-05-02' ... to (and excluding) random_text. I tried to achieve this through chosing the "anything but" structure to achieve this [^a]
(not a):
\'[^random]*
The above does not do the job, because random is not a string, but a set of characters, hence the 'r'
in the string will split my extracted value.
If there is no r
in the text before the word random_text, this would work fine:
\'[^r]*
Is there any way to include a specific string as the end of my sequence. e.g.
start: \'
repeated characters unlike string: [^{my_string}]*
Appreciate any insight :)
解决方案
This regex will do the job:
'.+'(?= random)
Just replace random
with the string you want to exclude at the end.
推荐阅读
- mysql - MySQL 查询 - 获取关注用户的所有评论
- visual-studio-code - 如何在不更改设置的情况下在 Visual Studio Code 中搜索 node_modules?
- go - go 支持多类型吗?(泛型类型)
- reactjs - 这两个 if-else 块和条件运算符块有什么区别?
- java - 顺便说一句,私人课程与 set 和 get 以及公共课程的区别
- angular - How to update index in from array cons body{} Angular 8
- python - 图形未显示在 conda 下的 Jupyter 全新安装和使用 viewscad 上游示例
- amazon-web-services - AWS 禁止 403
- kubernetes - 如何使用 manifest yaml 在 Kubernetes configmap 中挂载属性文件
- html - How to get to display database items in ejs/html using Nodejs/mongodb/mongoose?