Skip to Content

Match pattern is a function in validation transform. It is used to match the input strings. This function can be used to compare alphabets (a-z, A-Z), numbers (0-9) and special characters.

Match_pattern cannot be used to match sub-strings.




input_string is the string to be matched. It could be alphabets, numbers, etc.

pattern_string is the pattern that you want to find in the whole string.

Return value

The return value for this function is 0 or 1.

If the return value is 1 then the input string matches.

If the return value is 0 then the input string does not match.

The below table shows the examples with patterns:

Pattern with examples



  print(match_pattern(‘Janani’, ‘Xxxxxx’));

x – Used for lowercase alphabets.

Return value:1

  print(match_pattern(‘JANANI’, ‘Xxxxxx’));

  print(match_pattern(‘JANANI’, ‘XXXXXX’));

X – Used for uppercase letters.

Return value: 0

Return value:1

  print(Match_pattern(‘Jeni Krish’, ‘Xxxx Xxxxx’));

Return value:1


9 – Used for numbers

Return value:1



\  – Escape character. It is used to avoid a number specifically.

Return value:1 since number 3 is not found in the string.

Return value: 0 since number 3 is found in the string.


*- Used for characters appearing 0 or more times.

Return value:1



? — Characters occurring one and only once

Return value: 1 since after the character a only one character should appear.

Return value: 0 since after the character a many characters appear.



[ ]– Characters occurring inside the braces only one time.

Return value: 1 since character 1 is in the list of pattern string.

Return value: 0 since character 4 is not in the list of pattern string.

print(match_pattern(‘Akash’ , ‘[!A]’ ));

[!]–Any character but not the characters that appears after the exclamation point.

Eg: (i.e. [!AB] can allow any, say Name, that does not start with a A or B.

Return value: 0 since string starting with alphabet A should be avoided.

To report this post you need to login first.


You must be Logged on to comment or reply to a post.

    1. Former Member

      match_regex() is basically the same function but whereas match_pattern() returns a 1 or a 0, match_regex() returns the matched value. Both have their place and are both helpful. match_pattern() would probably be better used in validation.

      1. Former Member

        I think you will find that, unlike many other languages, match_regex() also returns an integer 0 / 1 indicating failure / success. One thing to note is that match_regex() matches against the whole string not just any location in the string, it is as if it wraps the ^ and $ anchors around the input regular expression.

        1. Former Member

          Yup, my bad. Agreed, match_regex() is much more powerful. Anything where you can use regular expressions over basic searches is preferable in my opinion.


Leave a Reply