Spreadsheet formula to extract substrings that match regular expressions: RE_REPLACE

Spreadsheet formula to extract substrings that match regular expressions: RE_REPLACE

book

Article ID: KB0083568

calendar_today

Updated On:

Products Versions
Spotfire Statistica 13.1,13.2,13.3

Description

Statistica spreadsheet formula to extract substrings that match regular expressions

Issue/Introduction

This article introduce usage of spreadsheet formula RE_REPLACE to extract substrings that match certain regular expressions.

Environment

Windows Server 2012 R2, Windows 7

Resolution

Visit this Statistica online help page on available Spreadsheet Formulas - Regular Expression Functions
  • RE_REPLACE(input_expr, reg_exp, replace_string, options) is to Replace portions of input_expr that match reg_exp with replace_string.
  • RE_REPLACE can also be used to extract/output the substrings that match reg_exp. The key is to use match groups () and then references to those match groups in the replace string ($1, $2, etc) for the 1st, 2nd, etc., groups. And the "c" option, which causes it to not copy to the output portions of the string which did not match.
For example: to extract the first substring that match the regular expression
=RE_REPLACE(V1, RegularExpressionPattern, "$1", "c")

User-added image
  • ​Note that by default, these use Perl-like syntax for regular expression patterns, so a google search for "Perl regular expressions" will give tons of documentation and examples.