Skip to content

[BUG] regex_match and regex_search should not require grouped regex #65722

Closed

Description

@vin01

Description

regex_match and regex_search do not return any match currently if a regex which does not use grouping using parentheses is used.

source of this behavior: https://github.com/saltstack/salt/blob/master/salt/utils/jinja.py#L501

Steps to Reproduce the behavior

regex_search('^1.abc$') would not return 1.abc despite a match.

Additional context

Possible fix: https://github.com/saltstack/salt/pull/65708/files

Activity

  1. added
    bug
    on Dec 17, 2023
  2. ipaqmaster commented on Apr 9, 2024

    @ipaqmaster
    Contributor

    Thanks for helping me figure this out for myself. I was trying to regex_match against a valid .*partial.* variable but salt refused to return a result (Either () or the variable being set as None).

    Wrapping the whole regex in parenthesis as (.*partial.*) has worked around the problem.

    This is on 3007.0 (Chlorine)

  3. ipaqmaster commented on Apr 9, 2024

    @ipaqmaster
    Contributor

    To clarify it looks like the string result () was still indicating a successful match on a regex string without parenthesis - but using it in a jinja if statement didn't evaluate as True. The None result seemed to occur when the regex truly didn't match.

    Its trivial to set a variable based on the regex_match result then test for != None, or piping more tests onto the end of the output. But that's a work around for this problem compared to having a single regex_match if statement which works without needing parenthesis in the regex string.

  4. added this to the Sulphur v3006.26 milestone on Jul 2, 2026
  5. dwoz commented on Jul 2, 2026

    @dwoz
    Contributor

    Fix merged and shipped in a supported release. Closing per bulk triage. Reopen if this reproduces on a currently supported release (3006.x, 3007.x, 3008.x, master).

  6. added a commit that references this issue on Jul 3, 2026
    4bb8398
  7. added a commit that references this issue on Aug 12, 2026
    713236d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions