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

Home » Public Forums » archive » Re: Using STREGEX/STRMID
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: Using STREGEX/STRMID [message #71277] Wed, 09 June 2010 14:01
fgg is currently offline  fgg
Messages: 67
Registered: April 2010
Member
On Jun 9, 12:23 pm, Craig Markwardt <craig.markwa...@gmail.com> wrote:
> On Jun 9, 2:19 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
>
>> Hello,
>
>> I'd like to get the "label" (i.e. 1033) from this string:
>
>> IDL> str = '; ROI name: EVF: Layer: pts_slant.shp (Label=1033)'
>
>> ...and I was wondering if there is a more elegant/efficient way of
>> doing this than:
>
>> IDL> pos0 = stregex(str, '=')+1
>> IDL> posn = stregex(str, ')')
>> IDL> print, strmid(str, pos0, posn-pos0)
>
> You want the substring option of STREGEX,
>
> str = stregex(str, '\(Label=([0-9]*)\)', /extract, /sub)
> print, str[1]
> 1033
>
> The zeroth substring is the full match.
> The first substring is the one enclosed in parentheses.  It's a little
> confusing because the () are used to enclose regex substrings and \(\)
> are the literal parentheses expected to appear in the string.
>
> Craig

Perfect. Thank you, Craig.
Re: Using STREGEX/STRMID [message #71280 is a reply to message #71277] Wed, 09 June 2010 12:23 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Jun 9, 2:19 pm, fgg <fabioguimaraesgoncal...@gmail.com> wrote:
> Hello,
>
> I'd like to get the "label" (i.e. 1033) from this string:
>
> IDL> str = '; ROI name: EVF: Layer: pts_slant.shp (Label=1033)'
>
> ...and I was wondering if there is a more elegant/efficient way of
> doing this than:
>
> IDL> pos0 = stregex(str, '=')+1
> IDL> posn = stregex(str, ')')
> IDL> print, strmid(str, pos0, posn-pos0)

You want the substring option of STREGEX,

str = stregex(str, '\(Label=([0-9]*)\)', /extract, /sub)
print, str[1]
1033

The zeroth substring is the full match.
The first substring is the one enclosed in parentheses. It's a little
confusing because the () are used to enclose regex substrings and \(\)
are the literal parentheses expected to appear in the string.

Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Object within an Object's Structure
Next Topic: Creating a sub array from an array

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

Current Time: Wed Oct 08 15:13:09 PDT 2025

Total time taken to generate the page: 0.00623 seconds