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 
Return to the default flat view Create a new topic Submit Reply
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
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: Thu Oct 09 20:42:24 PDT 2025

Total time taken to generate the page: 0.63632 seconds