Regular Expression for String representing DNA code

前端 未结 3 1562
慢半拍i
慢半拍i 2021-01-22 21:42

Hello I am trying to use regular expressions in a java program. I would like the regex to identify a String of unknown length and whose charachters are only \'C\', \'A\', \'G\'

3条回答
  •  花落未央
    2021-01-22 22:00

    Easy, just use a character class:

    [CAGT]+
    

    Or if the entire string has to comprise of the chars CAGT for it to match:

    ^[CAGT]+$
    

提交回复
热议问题