Regex Matches

Regex Matches searches for a pattern and returns as a result all matches that match the given pattern and thereby enables the user to get all occurences of a given expression inside an input text. The matches are returned by the activity as an IEnumerable of Strings, means a list of all matched expressions.

You can either search for a known or unknown expression and, in the case of the latter, define the pattern of the expression using our wizard.

 

Known Pattern

Step 1: Pattern configuration

  1. Firstly, you have to decide whether you want to provide a static keyword or search for the value of a variable.
  2. Secondly, you have to provide the necessary input (either the keyword itself or a variable containing the keyword).
  3. Under Configuration you can select the following check boxes:
    • Stand alone expression search: Your search is restricted to keywords that are located between word and non-word characters (e. g. a space or a colon). This might be helpful if you want to assure that you will only match a substring which consists of word characters and is enclosed by spaces (or any other non-word character). Instances where your pattern is enclosed by other word characters would not result in a match.
    • Case sensitive enabled: Differentiation between lower-case and upper-case letters (e. g. matches if pattern is “Test: word” and string is “Test: word”. This would not be the case if the string is “test: word”).

 

Step 2: Test pattern on example test

 

  1. Type your example text into the textbox (here: “This is a test”).
  2. Click on the Button Test.
  3. The table presents you the results based on the keyword which you generated in the first section Pattern Configuration (here: “test”). You will see all matches that were found in the table Results. If there is more than one match each result will be displayed on a separate line.

 

Step 3: Define output

  1. Check this box if you want the return the first match as a string.
  2. Check this box if you want to return all matches as IEnumerable<Match>. You can then use this output to proceed with the process (e. g. by iterating over these matches).
  3. Finally, select the variable(s) that should store your values.

 

Unknown Pattern

Step 1: Pattern configuration

  1. Select the type of the pattern you want to search for (Word, Text, Number, Integer, EmailAddress or TelephoneNumber).
    • Word: Matches one or more word characters (e. g. “my“ and “life“ in “my life“ but not “l.i.f.e“ in “my l.i.f.e“).

    • Text: Matches any character (except a new line) zero or more times.

    • Number: Matches any positive or negativ number with “.“ or “,“ as thousand/decimal separator (e. g. “1.787“, “-1,000.00“, “1“).

    • Integer: Matches any positive or negative whole number (e. g. “10“, “-23“ but not “2.2“, “1,000“).

    • EmailAddress: Matches all common email addresses with an @-sign in between and .xx, .xxx, .xxxx at the end (e. g. myemail@cmail.com but not “myemailcmail“, “myemail@cmail.c“).

    • TelephoneNumber: Matches one or more digits including the characters “+“, “*“, “#“, “(“, “)“ and “-“ (e. g. “+49 (0)170 8976768“ but not “1,700,000.00€“).

  2. Specify the position at which you expect your pattern to appear
    • After: You expect that your pattern appears after a given substring and you type this substring into the textbox next to After (e. g. if string = “[…] Your Email: max.mustermann@anothermonday.com […]“  you would check the box After and enter “Your Email: “ into the textbox)
    • Before: You expect that your pattern appears before a given substring and you type this substring into the textbox next to Before (e. g. if string = “[…] 78988776 (customer number) […]“ then you would check the box Before and enter “ (customer number)“ in the textbox)
  3. You can provide a minimal or/and maximal length of the pattern you are searching for. This length does not include any characters that appear after or before the pattern.
  4. Under Configurations you can select one or both of the following check boxes:
    • Stand alone expression search: Your search is restricted to patterns that are located between word and non-word characters (e. g. a space or a colon). This might be helpful if you want to assure that you will only match a substring which consists of word characters and is enclosed by spaces (or any other non-word character). Instances where your pattern is enclosed by other word characters would not result in a match (e. g. matches if pattern is “(c\w+)” and stand alone expression search is checked: “My cat cannot be replaced by a dog.” However, when you leave it unchecked the result will change: “My cat cannot be replaced by a dog.”).
    • Case sensitive enabled: Differentiation between lower-case and upper-case letters (e. g. matches if pattern is “Test: \s*(\w+)” and string is “Test: word”. This would not be the case if the string is “test: word”).
  5. The Pattern textbox shows you the Regex pattern that has been created as a result of your selection. If your pattern needs adjustment, this is the place to customize your pattern even further.

Step 2: Test pattern on example test

  1. Type your example text into the textbox (here: “This is a sentence.”)
  2. Click on the Button Test.
  3. The table presents you the results based on the pattern which you generated in the first section Pattern Configuration (here: “\s(\w+)\s(\w+)\s” (We search for two words separated and enclosed by spaces)).
    • Match: The first column shows you the index of the match. Since we have only one match in our example, all values are equal to 0 (remember that an index starts with 0 and not with 1).
    • Group: The second column shows you the indexes of the different groups of each match. Note that the index 0 always refers to the entire match.
    • Content: The final column shows you the actual content of your matches and their respective groups.

Step 3: Define output

  1. Check this box if you want the return the first match as a string.
  2. Check this box if you want to return all matches as IEnumerable<Match>. You can then use this output to proceed with the process (e. g. by iterating over these matches)).
  3. Finally, select the variable(s) that should store your values.
Was this article helpful?
0 out of 0 found this helpful