Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE (PHP <7.3)

/
^(chr)?(1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|X|Y)((:|\s+)\d+((-|\s+)\d+((_|\s+)[ACGT]+((\/|\s+)[ACGT]+)?)?)?)?$
/
i

Description

This expression matches human genomic coordinates, similat to those being used by genome browsers (e.g. the UCSC Genome Browser). It can match: chromosome, chromosome start, chromosome start end, chromosome start end reference sequence, chromosome start end reference sequence alternative sequence. The last two are useful when searching for mutations.

Examples: 1 # matches chromosome 1 chr1 # matches chromosome 1 1:12345 # matches chromosome 1, start at base 12345 chr11:12345-78900 # matches chromosome 1, start at base 12345, end at base 78900 chr11 12345 78900 # matches chromosome 1, start at base 12345, end at base 78900 11:12345-12345_A/G # matches chromosome 1, start at base 12345, end at base 12345 and a substitution of A to G 11 12345 12347 AG GC # matches chromosome 1, start at base 12345, end at base 12345 and a substitution of AG to GC

Submitted by Panagiotis Moulos - 8 years ago