Search code examples
regexmulemule-el

Regex in mule expressionlanguage


I would like to know the meaning of the regular expression used in mule expression language

I have a choice component that uses the following expression

regex('^[\\w\\s]+=.*',payload['Created_Package']) != null

Could some one please explain the meaning of the above expression?


Solution

  • The regular expression first starts at the beginning of the string, hence the ^ anchor, then matches any character that is considered a word character (a-z, A-Z, 0-9, _) or whitespace (1 or more times) followed by matching an equal = sign. Finally matching any character except newline (0 or more times)

    Some valid matches would be:

    foo=bar
    123=456
       =foo
    foo=&^&#$$#[]&^#
    

    Some invalid matches would be:

    *#*=dfds
    [foo]=bar
    1.2.3=456
    

    A good tool that offers explanation of a regular expression, Explain Regular Expression