Re: again strsplit [message #37730] |
Thu, 22 January 2004 08:11 |
tam
Messages: 48 Registered: February 2000
|
Member |
|
|
Reimar Bauer wrote:
> savoieNoSpam@nsidc.org wrote:
>
>> Reimar Bauer <R.Bauer@fz-juelich.de> writes:
>>
>>
>>> Hi all
>>>
>>> I have learned the /regex keyword but who could explain this:
>>>
>>> a='ABC$DEF'
>>> print,strsplit(a,'$',/extr)
>>>
>>> ABC DEF
>>>
>>> and
>>>
>>> a='ABC$DEF'
>>> print,strsplit(a,'$',/extr,/regex)
>>>
>>> ABC$DEF
>>>
>>>
>>> Why is this differnt?
>>
>>
>>
>> Because '$' is the regular expression for end of line. If you want to
>> have
>> the actual dollar sign, you need to escape it with a back slash first.
>> IDL> print,strsplit(a,'\$',/extr,/regex)
>> ABC DEF
>>
>> Helps?
>>
>> Matt
>>
>
>
> Dear all
>
> Thanks,
>
>
> Is there a function available which returns the key codes of regular
> expression signs.
>
> This is now a bit complicated. I have to use /regex because the
> separation could be done by more as one sign. But if it is a $ or
> something else of a regex code I have to add a \ sign in front.
>
> If a variable is used for the separator have I always to test on this?
>
> The old str_sep routine without regex was much clearer.
>
> regards
> Reimar
>
>
When dealing with regular expressions I normally escape all
non-alphanumeric characters. Not all of them are special, but it's
probably easiest to assume they are. It doesn't hurt to
escape a character that is not special (at least in
other languages).
Of course if you don't have a need for regular expressions, there
is no need to use that keyword.
Tom
|
|
|
Re: again strsplit [message #37734 is a reply to message #37730] |
Thu, 22 January 2004 06:59  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
savoieNoSpam@nsidc.org wrote:
> Reimar Bauer <R.Bauer@fz-juelich.de> writes:
>
>
>> Hi all
>>
>> I have learned the /regex keyword but who could explain this:
>>
>> a='ABC$DEF'
>> print,strsplit(a,'$',/extr)
>>
>> ABC DEF
>>
>> and
>>
>> a='ABC$DEF'
>> print,strsplit(a,'$',/extr,/regex)
>>
>> ABC$DEF
>>
>>
>> Why is this differnt?
>
>
> Because '$' is the regular expression for end of line. If you want to have
> the actual dollar sign, you need to escape it with a back slash first.
>
> IDL> print,strsplit(a,'\$',/extr,/regex)
> ABC DEF
>
> Helps?
>
> Matt
>
Dear all
Thanks,
Is there a function available which returns the key codes of regular
expression signs.
This is now a bit complicated. I have to use /regex because the
separation could be done by more as one sign. But if it is a $ or
something else of a regex code I have to add a \ sign in front.
If a variable is used for the separator have I always to test on this?
The old str_sep routine without regex was much clearer.
regards
Reimar
|
|
|
Re: again strsplit [message #37745 is a reply to message #37734] |
Wed, 21 January 2004 08:42  |
savoieNoSpam
Messages: 1 Registered: January 2004
|
Junior Member |
|
|
Reimar Bauer <R.Bauer@fz-juelich.de> writes:
> Hi all
>
> I have learned the /regex keyword but who could explain this:
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr)
>
> ABC DEF
>
> and
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr,/regex)
>
> ABC$DEF
>
>
> Why is this differnt?
Because '$' is the regular expression for end of line. If you want to have
the actual dollar sign, you need to escape it with a back slash first.
IDL> print,strsplit(a,'\$',/extr,/regex)
ABC DEF
Helps?
Matt
--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
|
|
|
Re: again strsplit [message #37748 is a reply to message #37745] |
Wed, 21 January 2004 06:48  |
tam
Messages: 48 Registered: February 2000
|
Member |
|
|
Reimar Bauer wrote:
> Hi all
>
> I have learned the /regex keyword but who could explain this:
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr)
>
> ABC DEF
>
> and
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr,/regex)
>
> ABC$DEF
>
>
> Why is this differnt?
>
>
> regards
>
> Reimar
Presuming IDL uses the same conventions for regular
expressions that have been popularized in Perl
I'd assume that if you've turned on regular expressions
that an unescaped $ has the special meaning of matching
the end of the string (and ^ the beginning).
So
print,strsplit(a,'f$', /extr, /regex)
will try to split on a terminal f and you should get
ABC$DE
as the result.
If you want to match with the character '$' then just escape
it with a backslash.
print,strsplit(a,'\$',/extr,/regex)
Regards,
Tom McGlynn
|
|
|
Re: again strsplit [message #37749 is a reply to message #37748] |
Wed, 21 January 2004 06:46  |
btt
Messages: 345 Registered: December 2000
|
Senior Member |
|
|
Reimar Bauer wrote:
> Hi all
>
> I have learned the /regex keyword but who could explain this:
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr)
>
> ABC DEF
>
> and
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr,/regex)
>
> ABC$DEF
>
>
> Why is this differnt?
>
Hi Reimar,
Funny, I was just fiddling with this, too.
I assume that you want to split the string into substrings using the '$'
character. To do so, you need to use the escape character
(backslash)before the '$' since '$' is also a REGEX control character.
IDL> a = 'ABC$DEF'
IDL> print,strsplit(a,'\$',/extr,/regex)
ABC DEF
Cheers,
Ben
|
|
|
Re: again strsplit [message #37750 is a reply to message #37749] |
Wed, 21 January 2004 06:45  |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
Hallo Reimar,
is not $ a special command character for regular expressions?
If you enclose it in [] braces, then it is not interpreted, I
think.
IDL> print,a
ABC$DEF
IDL> print,strsplit(a,'[$]',/extr,/regex)
ABC DEF
Cheers,
Paolo
Reimar Bauer wrote:
> Hi all
>
> I have learned the /regex keyword but who could explain this:
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr)
>
> ABC DEF
>
> and
>
> a='ABC$DEF'
> print,strsplit(a,'$',/extr,/regex)
>
> ABC$DEF
>
>
> Why is this differnt?
>
>
> regards
>
> Reimar
|
|
|