Get the App
SLTechnology News&Howtos  ›  Servers  › 

Various cases of regular expressions

Shulou Source: shulou.com Published: 2022-06-03 09:57:36 12月06日 Update

Find a blank line: ^ [\ t] * $\ r\ n

Find the 8-digit hexadecimal number in which the last digit is a lowercase letter: 0x [0-9] {7pr é 7} [amerz] {1mer 1}

Look for an 8-digit hexadecimal number with at least one lowercase letter: 0x (? = [0-9] {0prit 7} [a Murz]) [a-z0-9] {8jue 8}

Intercept all characters before the first parenthesis of the current line: (? = ^ [^ (| ^\ r | ^\ n] * [(| (]) ^ [^ () *)

Import re# looks for 8-digit hexadecimal numbers with at least one lowercase letter And modify it to uppercase def hex_to_upper (hexStr): listHex = re.findall ("0x (? = [0-9] {0je 7} [a Murz]) [a-z0-9] {8jue 8}", hexStr) print listHex newStr = re.sub (r "0x (? = [0-9] {0cr 7} [a murz]) [a-z0-9] {8pm 8}", "0XLLLLLLLL", hexStr) for obj in listHex: '-', obj [2:] newStr = re.sub (r "0XLLLLLLLL",'0x main__': + obj [2:] .upper (), newStr, 1) return newStrif _ _ name__ = ='_ main__': a = "oei0x7822CDE2lwnfnsodf0x7822abe2lsdksdf1023900x98de293c988e9we0x98112931ii" print a print hex_to_upper (a)

Tags: Hexadecimal letters lowercase rare uppercase characters parentheses blank lines and will case regular expression Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information vpn Apple Shulou Tech Info