Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何从python中包含一系列字符的字符串中获取devnagri子字符串_Python 3.x_Unicode_Substring_Hindi - Fatal编程技术网

Python 3.x 如何从python中包含一系列字符的字符串中获取devnagri子字符串

Python 3.x 如何从python中包含一系列字符的字符串中获取devnagri子字符串,python-3.x,unicode,substring,hindi,Python 3.x,Unicode,Substring,Hindi,以下是我的示例字符串: string = 'this is a string 3.158 बात करना है' 我想要一个函数,它将此字符串作为参数并返回: 'बात करना है' 该模块允许您访问正则表达式中的unicode属性。因此,您可以使用\p{script=devnagri}属性来匹配devnagri字符devnagri字母的Windows XP alt代码介于2309和2416之间。 因此,您可以使用以下代码: s = 'this is a string 3.158 बा

以下是我的示例字符串:

string = 'this is a string 3.158 बात करना है'
我想要一个函数,它将此字符串作为参数并返回:

'बात करना है'

该模块允许您访问正则表达式中的unicode属性。因此,您可以使用\p{script=devnagri}属性来匹配devnagri字符

devnagri字母的Windows XP alt代码介于2309和2416之间。 因此,您可以使用以下代码:

s = 'this is a string 3.158 बात करना है'

for n,i in enumerate(s):
    if ( 2309 < ord(i) < 2416 ) or (i==' ') and ( 2309 < ord(s[n-1]) <2416 ):
        print(i,end='')
这是一个字符串3.158बात करना है' 对于n,枚举中的i:
如果(2309