问题标签 [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.
python - 正则表达式替换包含指定子字符串的单词
我正在尝试替换字符串中包含某个子字符串的单词。这是一个例子
我努力了
和
这里的正确方法是什么?
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?
python - re.findall -> Python 中的正则表达式
结果:
我想要类似的东西:
我怎样才能做到这一点?
python - Python正则表达式匹配一个人的身高
我正在尝试创建一个 python 正则表达式,它将匹配一个人的身高,以英尺和英寸为单位,由一个撇号分隔(例如 6'0)。就我的目的而言,有效高度在 4'0 和 6'11 之间:这是我目前所拥有的:
此正则表达式返回以下内容(我将只显示前几个匹配项):
我希望正则表达式返回以下内容:
我真的不确定问题是什么。我是正则表达式的新手,但我认为这与括号的用法有关。
python - Python 正则表达式 groupDict 与组的重复
想知道是否有一个函数match.groupdict()
可以捕获类似于match.captures
函数的重复。
当我运行此代码时:
我得到:
我想要的是这样的:
有这样做的功能还是我应该自己手动完成?
python - Python -- 检查命名的捕获组是否存在
我想知道测试命名捕获组是否存在的正确方法。具体来说,我有一个将编译的正则表达式作为参数的函数。正则表达式可能有也可能没有特定的命名组,命名组可能存在也可能不存在于传入的字符串中:
我想在不使用的情况下测试该组是否存在try
——因为这会使函数的其余部分短路,如果找不到命名的组,我仍然需要运行该函数