Re: Using STREGEX/STRMID [message #71277] |
Wed, 09 June 2010 14:01 |
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  |
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
|
|
|