在两个子字符串之间查找阿拉伯语字符串。

huangapple go评论70阅读模式
英文:

Finding a string between two substrings in arabic

问题

I want to extract يذهب.

我想提取 يذهب

英文:

I have a string

string = "الطالب يذهب الي الممدرسة"

I want to extract
يذهب
I have tried the following code:

import re
res = re.search('الي(.*)الطالب', string)
print(res.group(1))

But this doesn't work.

答案1

得分: 2

Switching the order of the substrings surrounding (.*) solves the problem:

string = "الطالب يذهب الي الممدرسة"

import re
res = re.search('الي(.*)الطالب', string)
print(res.group(1))

Output: ' يذهب '

(I suspect you simply misentered the regular expression due to the way bidirectional text is displayed on your system.)

If the letters are displayed in their isolated forms, with logical ordering from left to right (that is, in the same order as the surrounding Python code), the original (faulty) string would be this:

在两个子字符串之间查找阿拉伯语字符串。

and the corrected string would be this:

在两个子字符串之间查找阿拉伯语字符串。

英文:

Switching the order of the substrings surrounding (.*) solves the problem:

string = "الطالب يذهب الي الممدرسة"

import re
res = re.search('الطالب(.*)الي', string)
print(res.group(1))

Output: ' يذهب '

(I suspect you simply misentered the regular expression due to the way bidirectional text is displayed on your system.)

If the letters are displayed in their isolated forms, with logical ordering from left to right (that is, in the same order as the surrounding Python code), the original (faulty) string would be this

在两个子字符串之间查找阿拉伯语字符串。

and the corrected string would be this

在两个子字符串之间查找阿拉伯语字符串。

huangapple
  • 本文由 发表于 2023年5月21日 03:27:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定