Wednesday, 15 June 2011

regex - Matlab match a string with regular expression -



regex - Matlab match a string with regular expression -

i need process user input string matlab. know how allowed string can like, don't know how utilize regular expressions check valid strings. homecoming true valid input strings , false otherwise.

valid inputs start letter s or b followed blank space , contain number 1 20. examples valid strings read follows:

's 14' 'b 7' 'b 20'

examples invalid strings read follows:

's 24' % number big 's14' % missing space 'x 13' % wrong letter 'b 111' % number big / 3 digits number, 1 2 allowed.

i started line of code, seems close solution not quite:

regexp('s 26', '[sb] [1-20]', 'match')

it not work out, sees s 2 positive match, in reality input s 26 invalid.

^(?:s|b)\s(?:[1-9]|1[0-9]|20)$

try this.see demo.

http://regex101.com/r/wq1ow3/14

regex string matlab

No comments:

Post a Comment