python - R Regex,获取引号之间的字符串
问题描述
所以。我正在尝试Document is original
从下面的字符串中提取。
c:1:{s:7:"note";s:335:"Document is original-no need to register again";}
解决方案
两个想法:
做一些工作,得到该结构的大部分组件:
string <- 'c:1:{s:7:"note";s:335:"Document is original-no need to register again";}'
strcapture("(.*):(.*):(.*)",
strsplit(regmatches(string, gregexpr('(?<={)[^}]+(?=})', string, perl = TRUE))[[1]], ";")[[1]],
proto = list(s="", len=1L, x=""))
# s len x
# 1 s 7 "note"
# 2 s 335 "Document is original-no need to register again"
一种更简单的方法,也许更硬编码:
regmatches(string, gregexpr('(?<=")([^;"]+)(?=")', string, perl = TRUE))[[1]]
# [1] "note"
# [2] "Document is original-no need to register again"
从这里开始,您需要弄清楚如何关闭"note"
,然后也许strsplit(.., "-")
可以获取您想要的子字符串。
推荐阅读
- javascript - 如何从输入中获取价值并与本地存储数据比较价值以使电子邮件不重复?
- jquery - 暴露 loader webpack 插件
- intellij-idea - Intellij How to - 在创建运行配置时以编程方式在远程配置中为 PORT 和 HOST 参数注入自定义值
- javascript - React-Native 导航文件夹
- javascript - 如果我使用我的 Threejs 空白画布
- java - 停止旧进程在jobservice android java中创建新进程
- python - ijv mpmath 矩阵的稀疏矩阵表示(coo_matrix 等效)
- python - VS Code 继续选择 PowerShell 来运行 Python 脚本
- docker - 我们如何在 uWSGI 中设置最大日志文件数?
- windows - 跟踪失败的登录尝试 Windows Server