Re: Removing (or replacing) substrings in a string array [message #87264 is a reply to message #87262] |
Wed, 22 January 2014 07:19   |
Matthew Argall
Messages: 286 Registered: October 2011
|
Senior Member |
|
|
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
;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 ($)
|
|
|