联发科2022-数字IC岗
图片引用
https://deerchao.cn/tutorials/regex/regex.htm#escape
请问 \W*\s*input\s*wire\s*(\[\d+\:\d+\])\s*(\w+)\s*
可以匹配到下面哪些选项?
A input wire [3:0] num1
B // input wire num2
C // input wire [WIDTH-1:0] num3
D Input wire [10:0] num4
E input wire [BIT:0] num5
解答:
- 工作中用到了正则,用正则表达我想要的格式。甲方爸爸给了他们写的txt文件作为data输入,我给他们非常不标准的txt转成py,然后灌入脚本FPGA测试的时候用。
- 一边写一边查很艰难,所以学会正则表达很有用。
\d
是匹配一个数字(0到9)
\d+
是多个数字,形如 12、44、6763
排除C、E。Input
大写,排除D。B没有[]。\W
后面有个*
重复0次。所以选A。- 翻译
[]
,前面要加转义\
。
例如:deerchao\.cn
匹配deerchao.cn
,C:\\Windows
匹配C:\Windows
。
python里常用的正则函数
import re
#re.compile()
content = 'Hello, I am Jerry, from Chongqing, a montain city, nice to meet you……'
regex = re.compile('\w*o\w*')
x = regex.findall(content)
print(x)
# ['Hello', 'from', 'Chongqing', 'montain', 'to', 'you'] 含o的字符串
#re.sub()
s='大家好,我是一个程序员小白。I 'm so glad to introduce myself, and I’m 18 years old. Today is 2020/01/01. It is a wonderful DAY! @HHHHello,,,#111ComeHere222...66?AA?zz?——http://welcome.cn'
re.sub(r'http[:.]+\S+', '', s)
#"大家好,我是一个程序员小白。I 'm so glad to introduce myself, and I’m 18 years old. Today is 2020/01/01. It is a wonderful DAY! @HHHHello,,,#111ComeHere222...66?AA?zz?——"
#replace()
#re.findall()
#startswith('')