regexp_outkeys

Version 2.0.0.1 (11.9 KB) by Rik
Extend the regexp function for old Matlab releases
4 Downloads
Updated 12 Sep 2023

regexp_outkeys documentation

View regexp_outkeys on File Exchange Open in MATLAB Online

Table of contents

Description

This function extends the regexp function for old Matlab releases.
On older versions of Matlab the regexp function did not allow you to specify the output keys. This function has an implementation of the split, match, and tokens output keys, so they can be used on any version of Matlab or GNU Octave.

Note that the builtin regexp function is still used, so any limitation and bugs still apply. As an example; the lookaround assertions ((?<=test)expr etc) were introduced in v7 (R14) and are therefore not supported in this function either on v6.5.

Matlab/Octave

Syntax

out = regexp_outkeys(str,expression,outkey);
[out1,...,outN] = regexp_outkeys(str,expression,outkey1,...,outkeyN);
[___,startIndex] = regexp_outkeys(___);
[___,startIndex,endIndex] = regexp_outkeys(___);

Output arguments

Argument Description
out The result specified by the outkey:
'start': numeric array with the starting indices of the matches.
'end': numeric array with the ending indices of the matches.
'match': cellstr with the matches.
'split': cellstr with the non-matches.
'tokens': nested cellstr with the matched tokens.
startIndex Same result as 'start' outkey.
endIndex Same result as 'end' outkey.

Input arguments

Argument Description
str A char array containing the text to be searched.
expression Regular expression. See the documentation for regexp for more explanation.
outkey One of the supported outkeys: 'match', 'split', 'tokens', 'start', and 'end'. Duplicates are allowed.

Examples

A few examples of valid syntax options:

str = 'lorem1 ipsum1.2 dolor3 sit amet 99 ';
words = regexp_outkeys(str,' ','split')
numbers = regexp_outkeys(str,'[0-9.]*','match')
RawTokens = regexp_outkeys(str,'([a-z]+)[0-9]','tokens');
words_with_number = horzcat(RawTokens{:})
[white,end1,start,end2] = regexp_outkeys(str,' ','match','end')

Compatibility, version info, and licence

Compatibility considerations:

  • Only the 'match', 'split', 'tokens', 'start', and 'end' options are supported. The additional options provided by regexp are also not implemented.
  • Cell array input is not supported.
Test suite result Windows Linux MacOS
Matlab R2022b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2022a W11 : Pass
Matlab R2021b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2021a W11 : Pass
Matlab R2020b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2020a W11 : Pass
Matlab R2019b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2019a W11 : Pass
Matlab R2018a W11 : Pass ubuntu_22.04 : Pass
Matlab R2017b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2016b W11 : Pass ubuntu_22.04 : Pass Monterey : Pass
Matlab R2015a W11 : Pass ubuntu_22.04 : Pass
Matlab R2013b W11 : Pass
Matlab R2007b W11 : Pass
Matlab 6.5 (R13) W11 : Pass
Octave 8.2.0 W11 : Pass
Octave 7.2.0 W11 : Pass
Octave 6.2.0 W11 : Pass ubuntu_22.04 : Pass Catalina : Pass
Octave 5.2.0 W11 : Pass
Octave 4.4.1 W11 : Pass Catalina : Pass
Version: 2.0.0.1
Date:    2023-09-12
Author:  H.J. Wisselink
Licence: CC by-nc-sa 4.0 ( https://creativecommons.org/licenses/by-nc-sa/4.0 )
Email = 'h_j_wisselink*alumnus_utwente_nl';
Real_email = regexprep(Email,{'*','_'},{'@','.'})

Test suite

The tester is included so you can test if your own modifications would introduce any bugs. These tests form the basis for the compatibility table above. Note that functions may be different between the tester version and the normal function. Make sure to apply any modifications to both.

Cite As

Rik (2024). regexp_outkeys (https://github.com/thrynae/regexp_outkeys/releases/tag/v2.0.0.1), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with R13SP1 and later releases
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
2.0.0.1

See release notes for this release on GitHub: https://github.com/thrynae/regexp_outkeys/releases/tag/v2.0.0.1

2.0.0

See release notes for this release on GitHub: https://github.com/thrynae/regexp_outkeys/releases/tag/v2.0.0

1.1.0

See release notes for this release on GitHub: https://github.com/thrynae/regexp_outkeys/releases/tag/v1.1.0

1.0.1

See release notes for this release on GitHub: https://github.com/thrynae/regexp_outkeys/releases/tag/1.0.1

1.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.