Crow Canyon Software Forum

Forum Navigation
Please or Register to create posts and topics.

Regextract() to copy the first part of string

In a NITRO form we need to copy one column to another column, but limit it to the first 20 characters. I can't seem get the regextract() function to work.

The formula I'm using is: $regextract([DisplayName|InternalName],@.{0,20})   but it returns nothing.
I've also tried this:             $regextract([DisplayName|InternalName],@.{20})       and it will copy the first 20 characters, but only if the string is longer than 20 characters as it should.

Interestingly, if I use the expression builder in Custom Actions it works correctly.

How can I copy the first (up to) 20 characters in a string?
Thanks for the help!

Uploaded files:
  • 2023-02-01-08_59_59-RegextractExample.png

Hi @pf-amalin

I ran this through ChatGPT and got the following response:

No, this regular expression wouldn't work. The expression .{0,20} matches zero to 20 occurrences of any character, but it matches from the start of the string. So, if the string is less than 20 characters long, it would match the entire string.

The correct regular expression to match the first 20 characters in a string would be ^.{0,20}. The ^ character matches the start of the string, so it ensures that only the first 20 characters are matched, even if the string is less than 20 characters long.

Can you try it with the '^' at the beginning instead of '@'? Or are you trying to get the first 20 characters after the '@' symbol?

I agree that ^.{0,20} is the correct regular expression and that's what I started with, I tested it here: https://regex101.com/r/R46CzM/1, but it returns nothing in NITRO when used like this: $regextract([DisplayName|InternalName],^.{0,20}). I'm not sure what the @ sign is for, but it is at the beginning of all the NITRO regextract examples I've seen so I've tried to include it. BTW, I tried several combinations before submitting this questions, including:

^.{0,20} <===This one should work
@.^.{0,20}
@.{0,20}
@^.{0,20}
@.^{0,20}

If I use the expression builder in Custom Actions it works correctly and displays this: ~~$regextract([DisplayName], "^.{0,20}")~~, so I exported that Custom Action and looked at the .xml file and found this:

~~{"ExpType":"Function",
"ExpValue":"regextract",
"Parameters":[{"ExpType":"ListItem",
"ExpValue":"InternalName",
"Parameters":[]},
{"ExpType":"FixedValue",
"ExpValue":"^.{0,20}",
"Parameters":[]}]}~~

but I couln't determine how to build a manual regextract() from this format.

Any update on the proper syntax for this expression? I'm simply trying to capture the first 20 characters of a string column.

$regextract([DisplayName|InternalName],^.{0,20})

The RegEx is correct and works apart from NITRO, but the NITRO regextract() function still does not work, see previous post for details.

 

Hi @pf-amalin,

^.{0,20} is the correct regular expression. It is not working directly with $regextract() function because the regular expression has a comma. Comma is a reserved character in NITRO.

Please find steps to update a column with first 20 characters extracted from a string in NITRO Forms using form event actions.

In this example, we have configured a form event action to extract first 20 characters from ‘Description’ column on column value change and update the output in ‘Subject’ column.

  1. Navigate to NITRO Forms designer for the list --> Expand ‘Advanced’ section (from right-hand panel) --> Form Event Actions. Configure FEA as shown below:

<Please refer uploaded file regex20_1.png>

2. Configure update form controls.

<Please refer uploaded file regex20_2.png>

3. Column value mapping.

Script used below:

var Value = _ccs_FormUI.fetchColumnValueUI("Column Internal Name");

var extractedValue = Value.slice(0, 20);

return extractedValue;

<Please refer uploaded file regex20_3.png>

4. Save settings --> Publish the NITRO Forms.

 

To add more details, we can map the ‘Subject’ column in Custom Actions and NITRO Workflows in below ways to get desired results:

  1. Using expression builder; that is explained in your first post.
  2. Specify the regular expression in a variable and use variable value in $regextract() function. Please find the steps below:
    1. Define a variable ‘expression’ with default value as @^.{0,20}
    2. Add column mapping for ‘Subject’ column in update item action settings as below:
      • Syntax: Column --> $regextract([Column Display Name|Column Internal Name],VariableName##value)
      • Example: Subject --> $regextract([Description|TextA],expression##value)

 

Uploaded files:
  • regex20_1.png
  • regex20_2.png
  • regex20_3.png

Thank  you, that's exactly what I was looking for!

Art