Skip to content
Discussion options

You must be logged in to vote

Jinja is Python under the hood, so you can use Python string methods directly on the value. Add .rstrip('_') at the end of your chain — it removes any number of trailing underscores, which is exactly what your replace(...) calls leave behind:

{{ row.replace(".",'')
.replace(".",'
')
.replace(" : ",'')
.replace(":",'')
.replace(",",'
')
.replace("?",'')
.replace("-", '')
.replace('/', '
')
.replace('(','')
.replace(')','')
.replace(' ', '
')
.replace('','')
.replace('
','')
.upper()
.rstrip('
') }}

If leading underscores can also appear (e.g. the value starts with a replaced character), add .lstrip('_') as well. Note that rstrip/lstrip operate on the string as a whole, so they're safe to use aft…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by FonixAU
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants