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

Home » Public Forums » archive » regular expressions (parsing strings)
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: Regular expression [message #53864 is a reply to message #36958] Fri, 04 May 2007 09:04 Go to previous messageGo to previous message
Foldy Lajos is currently offline  Foldy Lajos
Messages: 268
Registered: October 2001
Senior Member
On Fri, 4 May 2007, Lasse Clausen wrote:

> mhmm, don't understand. Ok, here we go: I have a string like this
>
> bb[23]
>
> where bb can be any combination of alphanumerics and the number can be
> anything. I am looking for the regular expression that will match the
> whole thing. My first idea was (at the moment I am not bothered about
> the order of the different parts):
>
> regex = '[a-zA-Z0-9\[\]]+'
>

This regexp searches for a bracket expression (a-zA-Z0-9\[\) followed by
one or more ]'s. (\ behaves as an ordinary character after the opening
bracket [, so the first ] is the closing bracket.)


> but alas!
>
> print, stregex('bb[23]', regex)
> 4
>

3 matches the bracket expr. and ] matches itself. So the answer is 4.


> What?! And any combination of omitting or changing the \ character
> will result in either IDL complainign about non-balanced brackets, a
> match at position 4 or it won't match.
>

Try something like this:

[a-zA-Z0-9]+ one ore more alphanumeric char
\[ [
[0-9]+ one or more digits
] }

ie:

regex = '[a-zA-Z0-9]+\[[0-9]+]'

regards,
lajos
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: KMean Clustering of RGB Images
Next Topic: Re: Add diagonal 1:1 line in a plot?

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

Current Time: Sat Oct 11 13:19:49 PDT 2025

Total time taken to generate the page: 1.28278 seconds