我如何检查字符串是否为像isalpha()这样返回布尔值的泰语

时间:2019-05-24 03:46:31

标签: python regex thai

我正在尝试通过使用# stream2.py import cv2 from threading import Timer import multiprocessing as mp # from yolov3 import YOLO class video(object): def __init__(self, name ): print(mp.current_process()) self.cap = cv2.VideoCapture(name) def run(self): self.timer = Timer(0.066, self.update) self.timer.start() def update(self): ret, frame = self.cap.read() if ret: cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break 或是否可以解决的任何方法来检查str只是泰语字符还是

我正在尝试使用

regex

切出另一种语言或数字 顺便说一下,它只是切片而不返回布尔值

我希望输出类似

re.compile(u"[^\u0E00-\u0E7F']|^'|'$|''")
ret = regexp_thai.sub("", s)

s = "engภาษาไทยที่มีสระ123!@" regexp_thai = re.compile(u"[^\u0E00-\u0E7F']|^'|'$|''") ret = regexp_thai.sub("", s) print(ret) # ภาษาไทยที่มีสระ print(isthai(ret)) # True 是泰语的unicode 如何编写u0E00-u0E7F函数

1 个答案:

答案 0 :(得分:0)

我不太确定所需的输出是什么。但是,我猜想我们想捕获大写字母,根据您的原始表达,我们可能只想添加一个简单的字符列表,将其与捕获组包装在一起,然后从左向右滑动我们想要的大写字母,也许类似于:

([\u0E00-\u0E7F]+)

DEMO

测试

# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility

import re

regex = r"([\u0E00-\u0E7F]+)"

test_str = "engภาษาไทยที่มีสระ123!@"

matches = re.finditer(regex, test_str, re.MULTILINE | re.UNICODE)

for matchNum, match in enumerate(matches, start=1):

    print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))

    for groupNum in range(0, len(match.groups())):
        groupNum = groupNum + 1

        print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))

# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

演示

const regex = /([\u0E00-\u0E7F]+)/gmu;
const str = `engภาษาไทยที่มีสระ123!@`;
let m;

while ((m = regex.exec(str)) !== null) {
    // This is necessary to avoid infinite loops with zero-width matches
    if (m.index === regex.lastIndex) {
        regex.lastIndex++;
    }
    
    // The result can be accessed through the `m`-variable.
    m.forEach((match, groupIndex) => {
        console.log(`Found match, group ${groupIndex}: ${match}`);
    });
}

RegEx

如果不需要此表达式,可以在regex101.com中对其进行修改或更改。

RegEx电路

jex.im可视化正则表达式:

enter image description here

参考

Regular Expression to accept all Thai characters and English letters in python