在Igbo语篇中寻找缩略词模式(*'*)

2024-09-25 08:28:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用regex在Igbo文本中提取wor'word形式的单词(我对regex真的不太了解)。例如

line = "jir’ọbara ya"

如果我这样做了

found = re.match("\w+’\w+", line)
print found.group()

我得到的是'NoneType' object has no attribute 'group',而不是jir’ọbara

然后,如果我做found = re.match("\w+’|\w+", line),它只给我jir’。你知道吗

关于如何解决这个问题或最好的其他方法有什么建议吗?谢谢。你知道吗


Tags: 文本rematchlinegroup单词形式regex
1条回答
网友
1楼 · 发布于 2024-09-25 08:28:44

如果行的格式一致,则:

wor, word = line.split()[0].split("’")

或者

>>> found = re.match("(\w+)’(\w+)", line)
>>> found.group(1)
'jir'
>>> found.group(2)
'ọbara'
>>> 

相关问题 更多 >