Regex match - MATLAB Cody - MATLAB Central

Problem 2811. Regex match

Difficulty:Rate

Many regular expression engines have a simple function to quickly know whether a regular expression entirely matches a string or not, for example C++ regex_match, python regex.fullmatch, and Java Pattern.matches. This is particularly useful for UIs that are only interested in validating strings.

Write such a function for MATLAB. As with other MATLAB's regex functions, this function should work with strings and cell arrays of strings.

Example

tf = regex_match('2015', '[0-9]+'); %is string only made of numbers?
    tf = true
tf = regex_match({'2015', '2015b', 'abc'}, '[0-9]+'); %match cell array against regex
    tf = [true false false]
tf = regex_match('2015', {'[0-9]+', '[A-Za-z]+'}); %match string agains cell array of regex
    tf = [true false]
tf = regex_match({'2015', 'abc'}, {'[0-9]+', '[A-Za-z]+'}); match cell against cell
    tf = [true true]

Note: calling java is forbidden

Solution Stats

33.85% Correct | 66.15% Incorrect
Last Solution submitted on Dec 23, 2024

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8

Problem Recent Solvers16

Suggested Problems

More from this Author9

Problem Tags

Community Treasure Hunt

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

Start Hunting!