简体   繁体   中英

compare regular expression with regular expression

I have a list of strings with a set size, for instance:

  1. ATTG
  2. ATGC
  3. ATNG
  4. ATTN

A, T, G and C are always the same, but N can take on every value. So i wanted to change them to regular expression:

  1. ATTG
  2. ATGC
  3. AT[ATCG]G
  4. ATT[ATCG]

And now i want to be able to say: value 1,3 and 4 are equal, and value 2 is unique. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM