4.82 regexpfx - Prefix of Match String

Format 1: regexpfx($str$,regular expression)

Format 2: regexpfx($str$,regular expression)

Return the prefix (substring before character string) of the longest substring where the defined regular expression matches with the character string $str$. When the same character string and regular expression is used with the three functions to extract different parts of the string in sequential order, namely regexpfx function,regexstr function, and regexsfx function, the original string can be restored by merging the resulting character strings from the functions. Use the regexpfxw function if $str$ or regular expression contain multibyte characters, or when characters in Shift_JIS encoding does not correspond to search results.

Example

Example 1: Basic Example

Find out the prefix of the longest substring that matches with the regular expression c.*a. For example, in record id=4, the function matches cabbca in the column and returns the prefix ba. Since the same input data and substring are used in the regexstr,regexpfx function, it is easy to compare the results.

$ more dat1.csv
id,str
1,xcbbbayy
2,xxcbaay
3,
4,bacabbca
$ mcal c='regexpfx($s{str},"c.*a")' a=rsl i=dat1.csv o=rsl1.csv
#END# kgcal a=rsl c=regexpfx($s{str},"c.*a") i=dat1.csv o=rsl1.csv
$ more rsl1.csv
id,str,rsl
1,xcbbbayy,x
2,xxcbaay,xx
3,,
4,bacabbca,ba