I want to know what is the use of /begin and /end in the pattern for a regex.. For eg:
pattern = /begin ONE (\w*) /end ONE;
regexp(text,pattern,'match')
Could someone please explain.
Best Answer
The / character and "begin" and "end" have no special significance in regexp: they are just plain text characters.
Which is to say that the /begin and /end are looking for those literal strings in the text.
That bit of code is looking for the literal characters /begin followed by one space, followed by the literal word ONE followed by one space.
Then the (\w*) means (in this context) that what is matched by the inside of the () is what is to be returned by regexp. What is inside the () is \w* which means a sequence of zero or more "word" characters. "word" characters are any alphabetic characters (including in non-English alphabets), together with the numeric digits 0 through 9, together with underscore -- very similar to the MATLAB identifier rule, except MATLAB identifiers do not permit non-English alphabetic characters.
After the "word", the expression expects one space and then the literal characters /end ONE
should do it. It matches any sequence of anything but closing brackets preceded by an opening bracket. Note that the opening bracket has to be escaped as it's a special character in regexes.
Best Answer