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

Home » Public Forums » archive » Stregex question - extracting substring
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: Stregex question - extracting substring [message #87016 is a reply to message #87013] Fri, 20 December 2013 07:53 Go to previous message
PMan is currently offline  PMan
Messages: 61
Registered: January 2011
Member
On Thursday, December 19, 2013 5:31:40 PM UTC-5, Phillip Bitzer wrote:
> OK, how about a STREGEX solution:
>
>
>
> str = ['xxxxxxx:yyy', 'xxxxxxx:yyyyyyy', 'x:yyyy'] ;define the string array
>
>
>
> yStrColon = STREGEX(str, ':.+$', /EXTRACT) ;get everything past the colon, including the colon
>
>
>
> yStr = STRMID(yStrColon, 1) ;strip the colon
>
>
>
> About that regular expression:
>
>
>
> : get the substring starting with the colon
>
> .+ get one or more instances of the "dot" (so, any character)
>
> $ anchor at the end of the string

I figured out my solution, just moments after my post (isn't that always the case??) Here is what I did, which is similar to Philip's approach:

I was starting with an array of strings, hence the indices at the end:
x = (stregex(splLines, ':(.*)$' , /extract, /sub))[1, *]

(x = (stregex(splLines, ':(.*)$' , /extract, /sub))[1] for a single string)

The () encapsulates what the /sub extracts and [1] index gets the subexpression only, the 0th element starts with the colon, which I did not want.

Thanks for the reply to my short-lived post!
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDL 8.3 released
Next Topic: Problems with Retain on OS X Mavericks

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

Current Time: Wed Oct 08 19:21:30 PDT 2025

Total time taken to generate the page: 0.00470 seconds