问题标签 [python-regex]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
76 浏览

python - 正则表达式替换包含指定子字符串的单词

我正在尝试替换字符串中包含某个子字符串的单词。这是一个例子

我努力了

这里的正确方法是什么?

0 投票
1 回答
133 浏览

ansible - Ansible regex_findall is not giving expected results with negative search

My ansible negative regex is returning everything

So I'm getting results of dns names from JSON, of which I'm trying to sort to create an automated ansible inventory. I have servers with naming schemes such as:

I'm getting the "v" servers divided out by environment, then I want to create a catchall group that is not the "v" servers So! I'm attempting to do:

Which does seem to work when I plug it into https://pythex.org. But ansible is returning everything instead... What the heck am I doing wrong here?

0 投票
2 回答
72 浏览

python - re.findall -> Python 中的正则表达式

结果:

我想要类似的东西:

我怎样才能做到这一点?

0 投票
1 回答
80 浏览

python - 如何使正则表达式方法超时?

我正在使用正则表达式模块的几种方法。我需要为多个编译模式设置超时,但尽管来自文档的示例,我无法重现执行以下操作的异常:

它没有TimeoutError像预期的那样上升。

我在 Microsoft WSL2 中的 Ubuntu 20.04 LTS 上使用 python 3.8。我也发现了这个相关的问题,但它没有帮助。我该如何解决这个问题?

0 投票
2 回答
38 浏览

python - Python正则表达式匹配一个人的身高

我正在尝试创建一个 python 正则表达式,它将匹配一个人的身高,以英尺和英寸为单位,由一个撇号分隔(例如 6'0)。就我的目的而言,有效高度在 4'0 和 6'11 之间:这是我目前所拥有的:

此正则表达式返回以下内容(我将只显示前几个匹配项):

我希望正则表达式返回以下内容:

我真的不确定问题是什么。我是正则表达式的新手,但我认为这与括号的用法有关。

0 投票
1 回答
27 浏览

python - Python 正则表达式 groupDict 与组的重复

想知道是否有一个函数match.groupdict()可以捕获类似于match.captures函数的重复。

当我运行此代码时:

我得到:

我想要的是这样的:

有这样做的功能还是我应该自己手动完成?

0 投票
1 回答
61 浏览

python - 使用 PyPi 正则表达式包无法将数字范围与 DEFINE 块中声明的模式匹配

我正在使用https://github.com/mrabarnett/mrab-regex(通过pip install regex,但在这里遇到了失败:

给出:

它错过了第二个值。

0 投票
2 回答
46 浏览

python - Python -- 检查命名的捕获组是否存在

我想知道测试命名捕获组是否存在的正确方法。具体来说,我有一个将编译的正则表达式作为参数的函数。正则表达式可能有也可能没有特定的命名组,命名组可能存在也可能不存在于传入的字符串中:

我想在不使用的情况下测试该组是否存在try——因为这会使函数的其余部分短路,如果找不到命名的组,我仍然需要运行该函数