I have a shell task that registers data that looks similar to:
“stdout_lines”: [
“username\tuseremail@domain.tld”,
“username\tuseremail@domain.tld”,
“username\tuseremail@domain.tld”,
“username\tuseremail@domain.tld”,
…,
]
What I’d really like to end up with is a variable that contains a list/has similar to { username: “username”, emailprefix: “useremail”, emaildomain: “domain.tld” }, { username: “username”, emailprefix: “useremail”, emaildomain: “domain.tld” }, … { username: “username”, emailprefix: “useremail”, emaildomain: “domain.tld” }
Currently I’ve been trying to get the “useremail” part of each of those lines out so I can do something with it.
So far I’ve tried using this regex “\t[a-zA-Z-]+@” and the regex_replace and match jinja filters.
match returns true or false as far as I can tell.
regex_replace lets me easily replace “useremail” with something, but not actually get “useremail” out of it.
For example, I can replace “useremail” with a space like this:
- debug: msg=“{{ item|regex_replace(‘\t[a-zA-Z-]+@’,’ ') }}”
with_items: userinfo.stdout_lines
But that’s not very helpful…
Any suggestions on how I can get what I want?
Note that the regex above also matches the \t and @ characters when tested on regexpal.com.