stregex fails to match underscore [message #88228] |
Mon, 31 March 2014 13:12  |
PMan
Messages: 61 Registered: January 2011
|
Member |
|
|
I am trying to use stregex to match a filename. I am curious why, after the
'([LLC|KGD|GFC|FFC])' portion of my search string, the first '_' does not match.
For example:
name = 'GDP1_XXX__KGD_RF.xml'
searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])'
print, stregex(name, searchStr, /boolean) ; Match
searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])_'
print, stregex(name, searchStr, /boolean) ; Not Match
Not sure why this happens. Anyone have any ideas?
Thanks.
|
|
|
Re: stregex fails to match underscore [message #88229 is a reply to message #88228] |
Mon, 31 March 2014 13:23   |
Lajos Foldy
Messages: 176 Registered: December 2011
|
Senior Member |
|
|
On Monday, March 31, 2014 10:12:46 PM UTC+2, Paul Mallas wrote:
> I am trying to use stregex to match a filename. I am curious why, after the
>
> '([LLC|KGD|GFC|FFC])' portion of my search string, the first '_' does not match.
>
> For example:
>
> name = 'GDP1_XXX__KGD_RF.xml'
> searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])'
> print, stregex(name, searchStr, /boolean) ; Match
>
> searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])_'
> print, stregex(name, searchStr, /boolean) ; Not Match
>
> Not sure why this happens. Anyone have any ideas?
([LLC|KGD|GFC|FFC]) matches a single character. Omit the brackets:
searchStr = '^G[DS]P1_XXX__(LLC|KGD|GFC|FFC)_'
regards,
Lajos
|
|
|
Re: stregex fails to match underscore [message #88230 is a reply to message #88228] |
Mon, 31 March 2014 13:26   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 3/31/14, 2:12 PM, Paul Mallas wrote:
> I am trying to use stregex to match a filename. I am curious why, after the
> '([LLC|KGD|GFC|FFC])' portion of my search string, the first '_' does not match.
>
> For example:
>
> name = 'GDP1_XXX__KGD_RF.xml'
> searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])'
> print, stregex(name, searchStr, /boolean) ; Match
>
> searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])_'
> print, stregex(name, searchStr, /boolean) ; Not Match
>
> Not sure why this happens. Anyone have any ideas?
>
> Thanks.
>
You want just alternation (parens), no character classes (square
brackets) in the LLC|KGD|GFC|FFC choice:
IDL> searchStr = '^G[DS]P1_XXX__(LLC|KGD|GFC|FFC)_'
IDL> print, stregex(name, searchStr, /boolean) ; Not Match
1
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|
Re: stregex fails to match underscore [message #88231 is a reply to message #88230] |
Mon, 31 March 2014 13:34  |
PMan
Messages: 61 Registered: January 2011
|
Member |
|
|
On Monday, March 31, 2014 4:26:23 PM UTC-4, Mike Galloy wrote:
> On 3/31/14, 2:12 PM, Paul Mallas wrote:
>
>> I am trying to use stregex to match a filename. I am curious why, after the
>
>> '([LLC|KGD|GFC|FFC])' portion of my search string, the first '_' does not match.
>
>>
>
>> For example:
>
>>
>
>> name = 'GDP1_XXX__KGD_RF.xml'
>
>> searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])'
>
>> print, stregex(name, searchStr, /boolean) ; Match
>
>>
>
>> searchStr = '^G[DS]P1_XXX__([LLC|KGD|GFC|FFC])_'
>
>> print, stregex(name, searchStr, /boolean) ; Not Match
>
>>
>
>> Not sure why this happens. Anyone have any ideas?
>
>>
>
>> Thanks.
>
>>
>
>
>
> You want just alternation (parens), no character classes (square
>
> brackets) in the LLC|KGD|GFC|FFC choice:
>
>
>
> IDL> searchStr = '^G[DS]P1_XXX__(LLC|KGD|GFC|FFC)_'
>
> IDL> print, stregex(name, searchStr, /boolean) ; Not Match
>
> 1
>
>
>
> Mike
>
> --
>
> Michael Galloy
>
> www.michaelgalloy.com
>
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
>
> Research Mathematician
>
> Tech-X Corporation
Ah, yes. Works fine that way. From the documentation I was expecting to dump the () and keep the [], but it's the other way around.
Thanks to you both.
|
|
|