我试图使用regex来匹配满足以下条件的东西:
不包含"//“字符串
含汉字
捡起那些汉字
我从一个文件中逐行读取:
f = open("test.js", 'r')
lines = f.readlines()
for line in lines:
matches = regex.findall(line)
if matches:
print(matches)
首先,我尝试使用以下模式来匹配汉字:
re.compile(r"[\u4e00-\u9fff]+")
它可以工作,并给我输出:
我遇到了一个问题,那就是如何反转包含这个‘a汉字efg’的字符串。
str_to_reverse = "abcd汉字efg"; /* those non-ASCII chars are Chinese characters, each of them takes 2 bytes */
恢复后,应该是:
str_toreverse = "gfe字汉dcba";
我想,为了反转字符串,我必须识别那些非ASCII字符,因为我认为简单地反转每个字节并不能得到正确的答案。
我该怎么做呢?
PS:这个程序是我在Ubuntu下写的,32位。然后我打印了每一个字节:
for(i
我试图在节点中创建一个带有opentype.js的字体子集
我的代码
const fs = require('fs');
const opentype = require('opentype.js');
let font = opentype.loadSync('./SourceHanSansCN-Heavy.otf');
let subfontGlyph = font.stringToGlyphs('一大段文字中文字体子集');
let subfont = new opentype.Font({
familyName: