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

Home » Public Forums » archive » stregex with multiple matches
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
stregex with multiple matches [message #88670] Thu, 29 May 2014 11:31 Go to next message
PMan is currently offline  PMan
Messages: 61
Registered: January 2011
Member
Hello,

Can stregex match an expression multiple times? It seems not, but I get the feeling there ought to be a way to do so. For example:


IDL> time_regex = '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'


IDL> timeStr = '10:21:41"
IDL> print, stregex(timeStr, time_regex)
0

Ok, that is what expected


IDL> timeStr = '10:21:41 - 11:32:00"
IDL> print, stregex(timeStr, time_regex)
0

But in the second example, why aren't there two matches? can I change my regex in some why to get multiple matches?

Thanks
Re: stregex with multiple matches [message #88671 is a reply to message #88670] Thu, 29 May 2014 11:41 Go to previous messageGo to next message
PMan is currently offline  PMan
Messages: 61
Registered: January 2011
Member
On Thursday, May 29, 2014 2:31:11 PM UTC-4, Paul Mallas wrote:
> Hello,
>
>
>
> Can stregex match an expression multiple times? It seems not, but I get the feeling there ought to be a way to do so. For example:
>
>
>
>
>
> IDL> time_regex = '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
>
>
>
>
>
> IDL> timeStr = '10:21:41"
>
> IDL> print, stregex(timeStr, time_regex)
>
> 0
>
>
>
> Ok, that is what expected
>
>
>
>
>
> IDL> timeStr = '10:21:41 - 11:32:00"
>
> IDL> print, stregex(timeStr, time_regex)
>
> 0
>
>
>
> But in the second example, why aren't there two matches? can I change my regex in some why to get multiple matches?
>
>
>
> Thanks

I just noticed the quote/double quote mis-match, but the result is the some
Re: stregex with multiple matches [message #88672 is a reply to message #88670] Thu, 29 May 2014 11:42 Go to previous messageGo to next message
PMan is currently offline  PMan
Messages: 61
Registered: January 2011
Member
On Thursday, May 29, 2014 2:31:11 PM UTC-4, Paul Mallas wrote:
> Hello,
>
>
>
> Can stregex match an expression multiple times? It seems not, but I get the feeling there ought to be a way to do so. For example:
>
>
>
>
>
> IDL> time_regex = '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])'
>
>
>
>
>
> IDL> timeStr = '10:21:41"
>
> IDL> print, stregex(timeStr, time_regex)
>
> 0
>
>
>
> Ok, that is what expected
>
>
>
>
>
> IDL> timeStr = '10:21:41 - 11:32:00"
>
> IDL> print, stregex(timeStr, time_regex)
>
> 0
>
>
>
> But in the second example, why aren't there two matches? can I change my regex in some why to get multiple matches?
>
>
>
> Thanks

I just noticed my quote/double quote mis-match, but the result is the same.
Re: stregex with multiple matches [message #88673 is a reply to message #88672] Thu, 29 May 2014 16:59 Go to previous message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
>> Can stregex match an expression multiple times?

Not that I am aware of. You have to repeat the search string twice (note I added "[^0-9]*" to the end of the regex).

nRepeats = 2
time_regex1 = '([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])[^0-9]*'
time_regex = strjoin(replicate(time_regex1, nRepeats))

timeStr = '10:21:41 - 11:32:00'
print, stregex(timeStr, time_regex, /SUBEXP, /EXTRACT)

-------------------
If you have no way of knowing how many times you will have, you can make the whole expression optional.

nRepeats = 5
time_regex1 = '(([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])[^0-9]*)?'
time_regex = strjoin(replicate(time_regex1, nRepeats))

timeStr = '10:21:41 - 11:32:00'
result = stregex(timeStr, time_regex, /SUBEXP, /EXTRACT)
for i = 0, 12 do print, result[i]

10:21:41 - 11:32:00
10:21:41 -
10
21
41
11:32:00
11
32
00
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: GDL workshop in France, 10-13 June 2014
Next Topic: Create an XML file in IDL

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

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

Total time taken to generate the page: 0.00604 seconds