[英]compare regular expression with regular expression
I have a list of strings with a set size, for instance: 我有一个具有固定大小的字符串列表,例如:
A, T, G and C are always the same, but N can take on every value. A,T,G和C始终相同,但N可以取所有值。 So i wanted to change them to regular expression: 所以我想将它们更改为正则表达式:
And now i want to be able to say: value 1,3 and 4 are equal, and value 2 is unique. 现在我想说:值1,3和4相等,值2是唯一的。 But how can you compare two regular expression to see if they are equal? 但是,如何比较两个正则表达式以查看它们是否相等?
i am currently programming in python 2.7, but if other languages are able to give the me results, i am willing to switch or run the code from command line. 我目前使用python 2.7进行编程,但是如果其他语言能够给我结果,我愿意从命令行切换或运行代码。
Why not do it yourself, since you are not actually using regular expression. 为什么不自己做,因为您实际上并没有使用正则表达式。 I guess you just only want to compare two sequences. 我猜你只想比较两个序列。
def match(a,b):
if a==b or a=='N' or b=='N':
return True
else:
return False
def compare(str1,str2):
if len(str1)!=len(str2):
return False
for i in range(len(str1)):
if not match(str1[i],str2[i]):
return False
return True
print compare('ATTG','ATNG')
# True
print compare('ATTN','ATGC')
# False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.