Behavior of the matlab regexptranslate function

Ben Abbott bpabbott at mac.com
Fri Mar 21 19:35:53 CDT 2008


On Mar 21, 2008, at 8:19 PM, David Bateman wrote:
> 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.

I just finished the install of 2008a. The results from 2008a and 2007b  
(the same) are below.

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

ans =

     'file1.mat file2.mat file3.xls file4.mat'

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

ans =

.*\.mat

Ben




More information about the Octave-maintainers mailing list