Issue
i would convert all the lines here @cat\n@chicken\napple\nfruit\njuice
into + : @cat : all\n+ :@chicken: all\n+ :apple : all\n+ : fruit : all\njuice : all
in other hand i would get this for every line + : value : all
i would use regex_replace
filter to perform the task, i don't have too much knowledge on python
, i am trying to do this:
{{ '@cat\n@chicken\napple\nfruit\njuice'| regex_replace('^(?P<name>)$', '\\g<name>: ALL' , multiline=True, ignorecase=True)}}
but nothing happens, i am missing something here
Solution
You can use
regex_replace(r'.+', r'+ : \g<0> : all' )
to wrap each non-empty line with + : <line_here> : all
text.
Note that .
matches CR chars, too, and if the line endings are CRLF, you will have to replace .
with [^\r\n]
.
Here, \g<0>
is a replacement backreference to the whole match value, no need using named capturing groups.
Answered By - Wiktor Stribiżew
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.