make a regex expression to select only numbers and commas in matlab

You can use the regexp function in MATLAB with the pattern '[0-9,]+' to select only numbers and commas in a string. This will match any substring containing one or more digits or commas. Here's an example:

main.m
str = '42, 101, 7, 999';
nums_and_commas = regexp(str, '[0-9,]+', 'match')
75 chars
3 lines

This will give you a cell array nums_and_commas containing:

main.m
{
    '42,'
    '101,'
    '7,'
    '999'
}
44 chars
7 lines

Note: In the regular expression pattern, [0-9] matches any digit, and , matches any comma. The + sign means to match one or more of the preceding pattern (digits or commas). The 'match' option returns all the matching substrings as separate strings in a cell array.

related categories

gistlibby LogSnag