我正在尝试使用以下代码来匹配文本est/(?P0-9{4})。
使用:
它匹配文本,但是在python中,它无法使用相同的表达式匹配相同的文本:
[^a-z0-9\/]
下面是包含这两个条件的代码。我不确定为什么在regexr.com中regEx会匹配,但在python中不匹配,除非有一个数字符号。
import os
import re
#no work
if re.match("[^a-z0-9\/]", "test/(?P<year>[0-9]{4})"):
print "match"
else:
print
在尝试学习更多关于正则表达式的知识时,有一篇教程建议您可以使用\b来匹配单词边界。但是,Python解释器中的以下代码片段无法按预期工作:
>>> x = 'one two three'
>>> y = re.search("\btwo\b", x)
如果匹配了任何内容,它应该是一个match对象,但它是None。
是\b表达式在Python中不受支持,还是我用错了?
我正在开始学习Python3,目前我完全迷上了‘正则表达式’。为了理解原始字符串,我编写了以下代码:
import re
pattern='\\n'
c='qwerty\. i am hungry. \n z'
d=r'qwerty\. i am hungry. \n z '
print(c)
print(d+'\n\n\n')
for a in (c,d,):
if re.search(pattern,a):
print('"{0}" contains "{1}"
我需要从一个句子中提取字符串"Jahr“之后的一年,并试图用正则表达式来实现这一点。
已证明在regex101:(?<=Jahr )[0-9]+上工作
但是,在python中,我使用的语法一定有问题:
import re
b = re.match(r"(?<=Jahr )[0-9]+", 'Example Jahr 2007 and more text')
print(b)
应产出:2007年
为什么这在python中不起作用?
我认为我在RegEx方面已经足够好了,我可以读到任何一个,但是这个简单的(用Python)让我很困惑。www.regexpal.com给出的结果与iPython不同。
data = 'four year entrepreneurial program. Students develop and run a business, gain much needed ...'
m = re.compile('entrepreneur|business\s(plan|model)')
m.findall(data)
给出['']
这怎么可能是对的?如果
我需要提取具有以下结构的URL中指定的ID:
https://trello.com/c/iGjJLqwr/1-test-project
在上面的示例中,我想提取:
iGjJLqwr
我需要使用Zapier中的regex表达式,根据文档使用Python regex。
下面的Python在某种程度上是正确的,但它仍然返回了太多:
[^https://trello.com/c/][\w]+
返回3次匹配:
Match 1
Full match 21-29 iGjJLqwr
Match 2
Full match 31-36 -test
Match 3
Full match 36-44
import nltk
text = """The Buddha, the Godhead, resides quite as comfortably in the circuits of a digital
computer or the gears of a cycle transmission as he does at the top of a mountain
or in the petals of a flower. To think otherwise is to demean the Buddha...which is
to demean onesel
我试图了解$在python 3.6的re模块中是如何工作的。
python文档说,'$' Matches the end of the string or just before the newline at the end of the string...,我并不完全理解。
你能给我一些re.match中$功能的基本例子吗?
在我的程序中,我尝试匹配一个包含两个字母的字符串,然后在它们之间匹配几个单词:在本例中,字符串"! hello my name !" "hello my name"可以将单词的数量更改为字符串,例如:"hello"或更多的单词。总之,我怎样才能匹配感叹号之间的字符串呢?主要问题是,我无法找到字符串匹配中要使用的表达式来表示长度未知的多个单词的字符串。
不知何故,我无法在网上找到任何关于如何将模式设置为double \n的内容。我的特殊情况如下。我有一根绳子:
"1 Matt\n00:00:00,100 --> 00:00:01,500\nThis is said \nby Matt.\n\n2 Lucas\n00:00:01,700 --> 00:00:02,300\nWhile this is said by Lucas"
我只想提取digit\n和\n\n之间的文本。所以,就我来说,我想
This is said \nby Matt.
While this is said by Lucas
虽然我对RegEx