Created
July 11, 2023 08:05
-
-
Save bhanpuramufaddal/ae768811542dd06bdc45feb9f34390cc to your computer and use it in GitHub Desktop.
Convert hex characters in a string back
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def convert_hex_char(string): | |
| decoded_string = bytes(string, 'utf-8').decode('unicode-escape') | |
| return decoded_string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def convert_hex_string(string): | |
| hex_pattern = r'\\x([0-9a-fA-F]{2})' | |
| hex_matches = re.findall(hex_pattern, string) | |
| for hex_match in hex_matches: | |
| string = string.replace(f'\\x{hex_match}', chr(int(hex_match, 16))) | |
| return string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment