quick strsplit question [message #59073] |
Thu, 06 March 2008 01:47  |
rlayberry
Messages: 33 Registered: November 2004
|
Member |
|
|
Hi
I am, trying to split an number of terms such as str9=dg_eyemouth.out
to take off the file extension
print,strsplit(str9,'.out',/extract,/regex)
but this gives
dg_eye h
any ideas
thanks
russ
|
|
|
Re: quick strsplit question [message #59196 is a reply to message #59073] |
Fri, 07 March 2008 05:56  |
rlayberry
Messages: 33 Registered: November 2004
|
Member |
|
|
On 6 Mar, 10:25, Nigel Wade <n...@ion.le.ac.uk> wrote:
> rlaybe...@hotmail.com wrote:
>> Hi
>
>> I am, trying to split an number of terms such as str9=dg_eyemouth.out
>
>> to take off the file extension
>
>> print,strsplit(str9,'.out',/extract,/regex)
>
>> but this gives
>
>> dg_eye h
>
>> any ideas
>
>> thanks
>
>> russ
>
> You've specified /regex. The character "." is a special character in a regex
> which matches anything. So ".out" will match "mout".
>
> You can remove the special nature of "." by preceding it with a backslash. You
> should probably also tie the match to the end of the string by appending a
> dollar:
> print,strsplit(str9,'\.out$',/extract,/regex).
>
> A better approach might be to use the function file_basename:
>
> print,file_basename(str9,[".out"])
>
great, thanks both of the above
|
|
|
Re: quick strsplit question [message #59220 is a reply to message #59073] |
Thu, 06 March 2008 02:25  |
Nigel Wade
Messages: 286 Registered: March 1998
|
Senior Member |
|
|
rlayberry@hotmail.com wrote:
> Hi
>
> I am, trying to split an number of terms such as str9=dg_eyemouth.out
>
> to take off the file extension
>
> print,strsplit(str9,'.out',/extract,/regex)
>
> but this gives
>
> dg_eye h
>
> any ideas
>
> thanks
>
> russ
You've specified /regex. The character "." is a special character in a regex
which matches anything. So ".out" will match "mout".
You can remove the special nature of "." by preceding it with a backslash. You
should probably also tie the match to the end of the string by appending a
dollar:
print,strsplit(str9,'\.out$',/extract,/regex).
A better approach might be to use the function file_basename:
print,file_basename(str9,[".out"])
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
|
|
|
Re: quick strsplit question [message #59221 is a reply to message #59073] |
Thu, 06 March 2008 02:07  |
Spon
Messages: 178 Registered: September 2007
|
Senior Member |
|
|
On Mar 6, 9:47 am, rlaybe...@hotmail.com wrote:
> Hi
>
> I am, trying to split an number of terms such as str9=dg_eyemouth.out
>
> to take off the file extension
>
> print,strsplit(str9,'.out',/extract,/regex)
>
> but this gives
>
> dg_eye h
>
> any ideas
>
> thanks
>
> russ
You want:
print,strsplit(str9,'\.out',/extract,/regex)
The '.' is a special character in regular expressions in IDL and needs
an escape character before it if you mean an actualy '.' in a string.
See the helpfile entitled 'Learning About Regular Expressions'.
Regards,
Chris
|
|
|