The new column returns the part of a string that matches a given regular expression. Optionally, you can add a capturing group to get a specific substring in case of several matches (being the capturing group 0 the first occurrence).
How does it work in the search window?
Select Create column in the search window toolbar, then select the Peek operation. You need to specify at least two arguments:
The data type of the values in the new column is string.
demo.ecommerce.data table, we want to extract only the days of our timestamp column. To do it, we will create a new column using the Peek operation.
The arguments needed to create the new column are:
- String - timestamp column
- Pattern - Click the pencil icon and enter .\d
- Capturing group - Click the pencil icon and enter 0
Click Create column and you will see the following result:
How does it work in LINQ?
Use the operator
as... and add the operation syntax to create the new column. This is the syntax for the Peek operation:
peek(string, re(string), capturing_group_integer)
peek(string, regexp, capturing_group_integer)
When you use the Peek operation in a LINQ query, you must use the Regular expression, regexp operation to transform the string value entered to regexp format. To do it, add the
re() syntax as in the above examples.
When you apply this operation in the search window interface, Devo automatically transforms your string value to regexp data type, so you don't need to do anything.
You can copy the following LINQ script and try the above example on the
from demo.ecommerce.data select peek(timestamp, re(".\\d"), 0) as timestamp_days