comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: again strsplit
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: again strsplit [message #37730] Thu, 22 January 2004 08:11
tam is currently offline  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 Go to previous message
R.Bauer is currently offline  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 Go to previous message
savoieNoSpam is currently offline  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 Go to previous message
tam is currently offline  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 Go to previous message
btt is currently offline  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 Go to previous message
Paolo Grigis is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: "Color vectors" & shading
Next Topic: Re: write unix textfile with windows idl

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:05:53 PDT 2025

Total time taken to generate the page: 0.00729 seconds