regex - 正则表达式:剪切可选的右侧
问题描述
我需要从日志文件中删除独立号码。例如,从右侧删除所有内容,从 1 个空格 + 1 个数字开始。
"process: 123" => text = "process:"
以下正则表达式完成工作:
^(?P<text>.*)\s\d
但是,如果没有空格 + 数字,我的正则表达式不会返回任何内容。如何扩展我的解决方案以满足以下 3 个要求?
"process: 123" => text = "process:"
"node4" => text = "node4"
"text without number" => text = "text without number"
解决方案
推荐阅读
- jsf - f:ajax 不更新组件
- javascript - 列表未在反应中更新
- html - 图标不会与文本元素对齐
- azure-active-directory - 使用守护程序 API 时获得 401 Unauthorized for plan
- domain-driven-design - 一组聚合的定义?
- spring - 无法在 Spring 示例中创建 EntityManager 对象
- regex - 如何在Ruby中用字母替换整数
- magento - 无法在 Windows 上安装 magento
- java - LocationListener 中的 onStatusChanged(String,int,Bundle) 已被弃用
- python - 在python中比较两个csv文件中的两列