Behavior of the matlab regexptranslate function

David Bateman adb014 at gmail.com
Fri Mar 21 19:19:35 CDT 2008


Ben Abbott wrote:
> 
> On Mar 21, 2008, at 4:02 PM, David Bateman wrote:
>> Ben Abbott wrote:
>>>
>>> David,
>>>
>>> I have a license, but have not yet installed it.
>>>
>>> Please post the tests, and if no one steps up, I'll install 2008a and
>>> run them.
>>>
>>> Ben
>>>
>>
>> Something like
>>
>> regexptranslate ('wildcard', '*a?b*c?')
> 
> ans =
> 
> .*a.b.*c.
> 
>> regexptranslate ('wildcard','?a*b?c*')
> 
> ans =
> 
> .a.*b.c.*
> 
>> regexptranslate ('wildcard','*a? *c?')
> 
> ans =
> 
> .*a. .*c.
> 
>> regexptranslate ('wildcard', '?a* ?c*')
> 
> ans =
> 
> .a.* .c.*
> 
>> regexptranslate ('escape', '.a/b\c[d]e$f(g)')
> 
> ans =
> 
> \.a/b\\c\[d\]e\$f\(g\)
> 
> I must admit, having just installed 2008a and never looked at what
> regexptranslate is intended to do, those results all look surprising.
> 
> Hopefully, they are what you expected?
> 
> Ben
> 
> 
They are the documented behavior. But rather useless as

regexp ('file1.mat file2.mat file3.xls file4.mat',
regexptranslate('wildcard','*.mat'), 'match')

will return

{'file1.mat file2.mat','file4.mat'}

rather than what the user probably wanted

{'file1.mat','file2.mat','file4.mat'}

and it doesn't follow the example in the documentation of

regexptranslate('wildcard','*.mat')

returning '\w+\.mat' which will produce the above. Maybe matlab special
cased the '*.mat' case and similar... What does the above return with
2008a? With 2008a it returns '.*\.mat'

D.



More information about the Octave-maintainers mailing list