I have trouble putting quotes to strings with the char @ and ends with the space, for example:
mystring = "@id string,@type string,account struct<@id string,@type string,accountId:string>"
mystring_expected = "`@id` string,`@type` string,account struct<`@id` string,`@type` string,accountId:string>"
How can I do it in Python?
>Solution :
you could use a regular expression to find the words and put quotes using the re.sub function:
import re
mystring = "@id string,@type string,account struct<@id string,@type string,accountId:string>"
pattern = r"(@\w+\b)"
mystring_expected = re.sub(pattern, r"`\1`", mystring)
print(mystring_expected)