Email format validation

Can someone please help with an example code how to validate email string format with regex?
I have a code that doesn’t work:

vars:
emailRegExpression: “[1]+@([\w-]+\.)+[\w-]{2,4}$”
emailAddress: “myemail@domain.com

tasks:

  • name: Validating email address
    set_fact:
    emailTest: “{{ emailAddress | regex_search(‘[2]+@([\w-]+\.)+[\w-]{2,4}$’) }}”
  • debug:
    var: emailTest

  1. \w-\. ↩︎

  2. \w-\. ↩︎

Try this:

Try this

    - assert:
        that: emailAddress is match(emailPattern)
        fail_msg: "{{ emailAddress }} is NOT valid email address."
        success_msg: "{{ emailAddress }} IS valid email address."
      vars:
        emailPattern: '^[\w\.]+@[\w\.]+[\w]{2,4}$'

Thank you, Dick! It worked!