Tag Archives: Regular Expressions

Regular Expression to Extract the First Part of a URL in Nintex Workflow

Using the Regular Expression action in Nintex Workflow, you can extract the first part of a URL and store it in a workflow variable to use in the rest of the workflow.

Follow these steps to build out this functionality:

  1. Add a Regular Expression action to the workflow.
  2. Configure the action with the following options:
    • Pattern = See examples in the table below
    • Ignore case = Check if string case should be ignored
    • Operation = Extract
    • Input text = URL string to extract data from (can be hard coded or inserted from the Insert Reference button)
    • Store result in = Create a “Single line of text” variable to use.
      • Note: The result is stored in a Collection variable. You will need to add another action like the “Collection Operation” action to get the result.
  3. Use the “Run Now” functionality to test the regular expression.

Examples
Below are the results when using each of the Patterns with this example URL in the “Input text” field:

https://DomainName.com/sites/SiteName/SubsiteName/ListName.aspx

PatternResult
(^https:\/\/[\w\d].[\w\d]*)https://DomainName.com
(^https:\/\/[\w\d].[\w\d]\/[\w\d]*)https://DomainName.com/sites
(^https:\/\/[\w\d].[\w\d]\/sites\/[\w\d]*)https://DomainName.com/sites/SiteName
(^https:\/\/[\w\d].[\w\d]\/[\w\d]\/SiteName\/[\w\d])https://DomainName.com/sites/SiteName/SubsiteName

How To Restrict Numeric Data Entered to a Certain Number of Digits in a Nintex Workflow Cloud Form (NWC)

You can easily configure a form field to only accept a certain number of digits as input. This configuration also will not allow text or special characters to be entered in the form field. This post will show you how configure this in a Nintex Workflow Cloud form. This solution can be useful to validate data like Account Numbers, Employee IDs, Invoice Numbers, and many other examples.

Follow these steps to build out this functionality:

  1. Add a Text – Short control to the form.
  2. Select “Regular expression” in the Input Validation setting drop-down menu.
  3. Enter the desired regular expression string in the Pattern field. Below are examples:
Restrict Number of Digits Entered to:Pattern:
5 digit number^(\d{5})$
7 or 8 digit number^(\d{7}|\d{8})$
9, 10, or 12 digit number^(\d{9}|\d{10}|\d{12})$
  1. Feel free to enter a message in the “Custom Regular expression message” field.
    1. This message displays if the data entered is not the correct number of digits.
    2. You can use this message as an instruction to the form user to correct the data.
  2. Test out this functionality by going to the Preview tab and adding data to the form field you configured.
    1. If you enter fewer or more digits than the pattern, the field is marked as invalid and the “Custom Regular expression message” appears under the field.
    2. If you enter text or special characters, the field will also be marked as invalid and the “Custom Regular expression message” appears under the field.
NWC Form Restrict Data Entered to Certain Number of Digits

Validate a Single Email Address Field in a Nintex Form

I recently built a Nintex Form that included a field where the user was asked to fill in their email address. The form needed to verify that the user was entering a valid email address.

This can be accomplished using a Regular Expression in the settings of the form control.  Below are the steps and Regular Expressions I used for validation the email address entered.

  1. Add a Single Line Textbox control to the form.
  2. Open the Control Settings and expand the Validation section.
  3. Change the “Use a regular expression” choice to Yes.
  4. Enter the one of the regular expressions below in the “Regular expression” field.
  5. Enter your custom validation message in the “Regular expression error message” field (for example, “Please enter a valid email address”).
  6. Save and publish the form.

Below is the main regular expression I have used to validate an email address on a form.

(?:[A-Za-z0-9!#$%&’*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&’*+/=?^_`{|}~-]+)*|”(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*”)@(?:(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[A-Za-z0-9-]*[A-Za-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

I have also used the regular expression below to validate an email address.  It’s much simpler but does not check as extensively for certain patterns.  It does check for a 2-4 domain extension after the period.

^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4};?)+$

Nintex Forms - Single Email Validation


Kudos to Eric Harris for first sharing this in his post on the Nintex Xchange site: Simple email validation for forms

Get a Parameter within a URL Using a Regular Expression in Nintex Workflow

Recently had a need to extract a parameter from within a URL string using Nintex Workflow.  Specifically, I needed to get the ID parameter from a URL.  In the example URL below, I needed to extract the number 987:

//mysite/mypage.aspx?ID=987&User=654

Follow these steps to get the ID number:

  1. Open the Nintex Workflow designer and add a Regular Expression action.
  2. Configure the Regular Expression action with the following settings:
    • Pattern =  (?<=ID=)[^&]+
    • Operation = Extract
    • Input Text = String, Inserted Reference or Workflow Variable
    • Store Result In = Collection workflow variable
    • Note: Your can use the “Run Now” option in the ribbon to test out the action.
  3. Next add a Collection Operation Action with the following settings:
    • Target Collection = Collection workflow variable
    • Operation = Get
    • Index = Integer workflow variable (with “Default value” = 0)
    • Store Result In = Text workflow variable
  4. The value (987 in the example) is stored in the Text workflow variable and can be used else where within your workflow.

Nintex Workflow Regular Expression - Extract Parameter from URL

Nintex Workflow Collection Operation - Extract Parameter from URL

Remove Line Breaks in Text Using a Regular Expression in Nintex Workflow

You can remove line breaks in a text string using the Regular Expression action in Nintex Workflow.

Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. Pattern = [\r\n]
    2. Replacement text = Keep this empty (or use a replacement character)
    3. Input text = Insert your text string (you can insert a reference to data in a list column or workflow variable)
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

RegExRemoveLineBreaks

Get Digits Before a Decimal Point Using a Regular Expression in Nintex Workflow

Using the Regular Expression action in Nintex Workflow, you can get the digits before a decimal point.

Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. String = Your number from a column or workflow variable.
    2. String Operation = Replace
    3. Pattern = \.[0-9]+
    4. Replacement String = Keep this empty
    5. Output = Text workflow vatiable
  3. You can then use the workflow variable as you need it.

Here are some examples from using this Regular Expression:

String Regular Expresssion Result
6.5 \.[0-9]+ 6
1234.5678 \.[0-9]+ 1234
1234567.89 \.[0-9]+ 1234567

 

Regular Expression to Get All Characters After a Specific Character in Nintex Workflow

You can get all the characters after a specific character in a string using Nintex Workflow.

Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. Pattern = (^.*?(?=-)-)  where the “-” is the character (replace both “-” with your desired character)
    2. Replacement text = Keep this empty
    3. Input text = Insert your text string (you can insert a reference to data in a list column or workflow variable)
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

Here are some examples from using this Regular Expression:

String Regular Expresssion Result
abc123-xyz456 (^.*?(?=-)-) xyz456
abc123;xyz456 (^.*?(?=;);) xyz456
abc123?xyz456 (^.*?(?=[?])[?]) xyz456

Remove a Forward Slash at the End of a URL String in Nintex Workflow

I recently had a need to remove a forward slash (“/”) from the end of a URL text string using Nintex Workflow.  Here are the steps to follow:

  1. Insert a Regular Expression action into your Nintex Workflow.
  2. Configure it with the following settings:
    1. Pattern = /[^/]*$
    2. Replacement text = Keep this empty
    3. Input text = Insert your URL text string
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

Remove Spaces from Text Strings with Nintex Workflow

You can easily remove all spaces in text strings in Nintex Workflows. Follow these steps:

  1. Insert a Regular Expression action into the workflow.
  2. Configure it with the following settings:
    1. Pattern = \s
    2. Replacement text = Keep this empty
    3. Input text = Insert your text string
    4. Store result in = Text workflow variable
  3. You can then use the workflow variable as you need it.

Error Creating an Item with a Person/Group Field in Nintex Workflow

Ran across an issue with a Nintex Workflow 2013 when using the “Create an item” action. The workflow runs when a list item is created and creates a document set in another list with metadata from the original item. One of the fields in the original item is a Person/Group field, which the workflow action uses as a field to bring over when creating the document set.

The workflow failed to create the item and gave the following error message:

Failed to create item. Invalid data has been used to update the list item. The field you are trying to update may be read only.

Resolution:

This issue seems to occur when using the “Create an item”, “Set field value” and “Update an item” actions.

Since the site uses forms based authentication, the value of the original Person/Group stored in a workflow comes over as:

i:0#.w|domain\username

Here are the steps I used to resolve this issue:

  1. Used a Regular Expression action to strip out the characters before the domain and stored the result in a workflow variable (UserNameOnly).
    • Pattern = i:0#.w[|]
    • Operation = Replace text
    • Replacement text = Leave empty
    • InputText = Original Person/Group field
    • Store result in = UserNameOnly
  2. Configured a Build String action to reformat the UserNameOnly variable to prepend it with -1;# and store it in the same variable.
    • Text = -1;#UserNameOnly
    • Store result in = UserNameOnly
  3. The resulting value from Step 2 of UserNameOnly is now -1;#domain\username.
  4. Reconfigured the “Create an item” action in the workflow to use the UserNameOnly workflow variable to update the Person/Group field of the new item.