[Python] Python RE ( In a word to check first letter is case sensitive and rest all case...

Discussão em 'Python' iniciado por Stack, Agosto 5, 2025.

  1. Stack

    Stack Membro Participativo

    In the below case i want to match string "Singapore" where "S" should always be capital and rest of the words may be in lower or in uppercase. but in the below string "s" is in lower case and it gets matched in search condition. can any body let me know how to implement this?

    import re
    st = "Information in sinGapore "

    if re.search("S""(?i)(ingapore)" , st):
    print "matched"

    Singapore => matched
    sIngapore => notmatched
    SinGapore => matched
    SINGAPORE => matched

    Continue reading...

Compartilhe esta Página