I'm a beginner so please forgive me for that question. I would like write program which magnifies letters between characters "<" and ">"
For example Input:
<html> randomchars </html>
Output:
<HTML> randomchars </HTML>
How to do that ?
I only wrote this but this magnifies all words.
while True:             
    inp = input()
    if inp == "":
        break
    elif inp =="<":
        inp=inp.upper()
        print(inp)
    else:
        print(inp)
Thanks for help.
Using index() + loop to extract string between two substrings. In this, we get the indices of both the substrings using index(), then a loop is used to iterate within the index to find the required string between them.
Python String upper() Method The upper() method returns a string where all characters are in upper case.
You can extract a substring in the range start <= x < stop with [start:step] . If start is omitted, the range is from the beginning, and if end is omitted, the range is to the end. You can also use negative values. If start > end , no error is raised and an empty character '' is extracted.
What is isupper() in Python. In Python, isupper() is a built-in method used for string handling. This method returns True if all characters in the string are uppercase, otherwise, returns “False”.
Try re.sub;
print re.sub(r"(</?\w+>)", lambda up: up.group(1).upper(), "<tag>input</tag>")
/?\w+ breakdown below, assuming you can see parenthesis () makes the group and we are trying to match between brackets <>;
? will greedily match 0 or 1 repetitions of the preceding RE.
Therefore, /? will match both start and finish tags.\w will match any Unicode word character, including a-z, A-Z, and 0-9.+ will greedily match 1 or more repetitions of the preceding RE.This will match most tags and then you can replace the tag after converting to uppercase inline using the lambda function, up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With