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

Home » Public Forums » archive » Removing (or replacing) substrings in a string array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Removing (or replacing) substrings in a string array [message #87270 is a reply to message #87264] Wed, 22 January 2014 07:34 Go to previous messageGo to previous message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den onsdagen den 22:e januari 2014 kl. 16:19:14 UTC+1 skrev Matthew Argall:
> I used the following site to learn about regular expressions. It is a bit wordy, but gets the job done.
> http://www.regular-expressions.info/tutorial.html

Thanks, I'll have a look at it.

> ;Strings
> myStr1 = '.aldfa09741_{}+=!@#$%^&*(.'
> myStr2 = 'aldfa09741_{}+=!@#$%^&*(.'
> myStr3 = '.aldfa09741_{}+=!@#$%^&*('
>
> ;Stregex
>
> regex1 = stregex(myStr1, '^\.?([^.]*)\.?$', /SUBEXP, /EXTRACT)
> regex2 = stregex(myStr2, '^\.?([^.]*)\.?$', /SUBEXP, /EXTRACT)
> regex3 = stregex(myStr3, '^\.?([^.]*)\.?$', /SUBEXP, /EXTRACT)
>
> ;Print
>
> print, regex1[1]
> print, regex2[1]
> print, regex3[1]
>
> '^\.?' -- look for an optional (?) dot (\.) at the beginning of the string (^)
> '([^.]*)' -- look for any character except the dot ([^.]) any number of times (*) and extract it ()
> '\.?$' -- look for an optional (?) dot (\.) at the end of the string ($)

Maybe that is part of the solution. I hadn't realized you can use the subexp that way. But it fails when there are more fields. The dots are (in general) the separators between multiple fields.

IDL> mystr4= 'gag.aldfa09741_{}+=!@#$%^&*(.sdf'
IDL> regex4 = stregex(myStr4, '^\.?([^.]*)\.?$', /SUBEXP, /EXTRACT)

Then regex4 is an array of two empty strings.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: keyword inheritance question
Next Topic: Plotting points in fainter color on an IDL plot

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

Current Time: Wed Oct 08 17:56:51 PDT 2025

Total time taken to generate the page: 0.00232 seconds