From: lily on
My question is how to use function regexprep to replace a whole string with a part of it.
K>> str='a_b_c.3d.6';regexprep(str,'\w?_(\w+)_\w+?','$1')
ans =
b.3d.6
What I want is only ‘b’,how to define the pattern?Thanks.
From: ImageAnalyst on
On Jul 3, 5:50 am, "lily " <mediocrity...(a)hotmail.com> wrote:
> My question is how to use function regexprep to replace a whole string with a part of it.
> K>> str='a_b_c.3d.6';regexprep(str,'\w?_(\w+)_\w+?','$1')
> ans =
> b.3d.6
> What I want is only ‘b’,how to define the pattern?Thanks.

-------------------------------------------------
Wouldn't that simply be:
str2 = str(3)
or,
underlinePositions = find(str == '_')
str3 = str(underlinePositions(1)+1)