1、7) Regular Expressions Ma3 Webster IMBIM, BMC ma3hew.webster@imbim.uu.se Regular expressions •Very powerful and useful part of perl •similar to find and replace in word, or grep in unix•used for pa3ern matching $_="ACGCGCTGCGTAGACATGGTAGACGAT";!if(/ATG/){!!pri
2、nt"Ifoundastartcodon";!}•a simple regular expression is something inside //!•you can use all the normal backlash codes e.g. /TGtchr10t128182/!!# a snp and it's posiIon? Metacharacterscharacters with a special meaning .! a dot is the wildcard (matches o
3、ne of everything except ) !!backslash changes any metacharacter into a normal character !/./!/t/!matches anything matches tab !!/./!/\t/!matches a dot matchest!!!/\/!/.t./!matches a backlash matches two characters with a tab in the middle More metac
4、haracters*!a star matches previous characters zero or more Ime !+!a plus matches previous characters one or more Imes ?!quesIon mark matches previous character zero or one Ime /Maja*/!matches Maj or Maja or Majaaaaa!!/Maj+a/!matches Maja or Majjjjjja!!/M?aja/
5、!matches Maja or aja!More metacharacters()!parentheses can be used to group parts of the pa3ern /(Maja)*/!matches nothing or Maja or MajaMaja or MajaMajaMajaMajaMaja!!/(Maj)+a/!matches Maja or MajMajMajMaja!!/M*(aja)+/!matches aja or MMMajaor MMMMajaajaajaaja
6、aja!More metacharacters12!backslash number is used to refer back to a parentheses that matches $_="EmmaIvansson";!!/(.)1/!matches two characters next to each other 'mm'!!/(E)mm(a).+2/!matches 'EmmaIva'!!/(E)mm(a).+1/!doesn't match!character classes []!a
7、list of possible characters goes inside square brackets /[a-z]/!matches one lowercase le3er (not åäö)!!/[a-zA-Z]/!matches one upper or lowercase le3er (not ÅÖÄåöä)!!/[ATGC]+/!matches a DNA sequence of any length ![^A-Z]+/!matches anything except capital le3
8、ers (^ negates) /[A-Z]+/!matches strings containing 'A', '-' and 'Z' (backslash stops dash being a special character) e.g. AAA---A---A----Z---Z----A----A-Z-AAAZAZ!character classes d!a