Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
34,261

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.

Syntax

match_pattern(input_string,pattern_string)

Here,

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

Use

Result

  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

print(Match_pattern(123,999));

9 - Used for numbers

Return value:1

print(match_pattern('jeni4','jeni[!\3]'));

print(match_pattern('jeni3','jeni[!\3]'));

\  - 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.

print(match_pattern('janani','*'));

*- Used for characters appearing 0 or more times.

Return value:1

print(match_pattern('a1','a?'));

print(match_pattern('a1sdf','a?'));

? -- 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.

print(match_pattern('a1','a[123]'));

print(match_pattern('a4','a[123]'));

[ ]-- 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.

8 Comments