Thursday, 23 March 2023

Automation - Regular Expression

 


Why we user Regular Expressions-

Regular expressions normally used for the comparison purpose.

Syntax -

 {REGEX["Your Regular Expression"]}

Below are the some examples in order to generate regular expressions -

Random Number & Combinations Generation -

 In automation some time we need to generate dynamic Random numbers in specific number format as per testing requirement in that case we can user below techniques to generate random numbers -

Example - Number starting with 0000 format.

Syntax - {RANDOMREGEX["Regular Expression"]}

Answer - {RANDOMREGEX["0000[0-9]{6}"]} => 0000345679

Example - Number starting with 0000 but then reset number should contain 0 in reset number. It should be 16 digit number.

Syntax - {RANDOMREGEX["0000[1-9]{12"]}

Answer - 0000136943887256

Example - Sometime we need to generate string with below format.

Payment Transaction-XXXXXX

Syntax - {RANDOMREGEX["Payment Transaction-[0-9]{6}]}

Answer - Payment Transaction-812673

Below are some sample patterns used to generate random string -

  1. ([A-Z][a-z][0-9]-) - Letters, numbers and hyphens.
  2. (\d{1,2}\/d{1,2}\/\d{4}) - Date ( e.g. 23/03/2023)
  3. ([^\s]+(?=\.(jpg|gif|png))\.\2) - jpg, gif or png image.
  4. (\w+@[a-zA-z_]+?\.[a-zA-Z]{2,6}) - Email Addresses.
Below are the character classes set -
  1. \c - Control character
  2. \s - White Space
  3. \S - Not white space
  4. \d - Digit
  5. \D - Not Digit
  6. \w - Word
  7. \W - Not word
  8. .\xhh - Hexadecimal character hh
  9. .\Oxxx - Octal character xxx
Below are the some Anchors -

  1. ^ - Start of line
  2. \A - Start of string
  3. $ - End of line
  4. \Z -End of string
  5. \< - Start of word
  6. \> - End of word



No comments:

Post a Comment

Remote Execution

  Article-1