Python Forum
Using re to find only uppercase letters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using re to find only uppercase letters
#1
Hi,
Im trying to solve a problem using re module, and one of the requests is to find a string with the letters ATGC only in uppercase.
this is my code:
def isVCF(file):
    num_format = re.compile(r"^chr(?:0?[1-9]|[1-9][0-9]|[MXY])\t0*[1-9][0-9]*\t[^\t]*(?:\t[ATCG]){2}\t")
    with open(file, "r+") as my_file:
        for line in my_file:
            if not num_format.match(line):
                return False
        return True
and this is an example to a line:
Output:
ChrX 74226540 T t 50 .
The problem is that its matching the lowercase "t" aswell and I only want it to find uppercase letters.
I've tried several things but none worked.
Appreciate any kind of help!
Reply


Messages In This Thread
Using re to find only uppercase letters - by ranbarr - May-27-2021, 05:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Uppercase problem MarcJuegos_YT 4 2,698 Aug-21-2020, 02:16 PM
Last Post: MarcJuegos_YT
  Check if string is uppercase or lowercase and eliminate Wolfpack2605 1 4,821 Jan-01-2018, 05:03 AM
Last Post: Mekire

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020