Applescript Is there a way to search for a time or date withi text

Discussion in 'Mac Programming' started by wild4life2013, Aug 5, 2013.

  1. macrumors newbie

    Joined:
    Mar 13, 2013
    #1
    I have a script that has a repeat loop that set a variable to some text I would like to be able to search that text and different information out. like any date it contains or times.

    thanks in advance for any help
     
  2. macrumors 6502

    superscape

    Joined:
    Feb 12, 2008
    Location:
    Yorkshire, UK
    #2
  3. thread starter macrumors newbie

    Joined:
    Mar 13, 2013
    #3
    thanks superscape ill check it out
     
  4. thread starter macrumors newbie

    Joined:
    Mar 13, 2013
    #4
    I extracted the time using the code below
    Code:
    set theText to "test of extracting the time 19:30 from all of the other text"
    set theOffset to offset of ":" in theText
    set num to theOffset - 2
    set thetime to text (theOffset + 2) thru num of theText
    this works well.
    couldn't work it out with the Satimage OSAX but have used it in other scripts.
     
  5. macrumors 6502

    superscape

    Joined:
    Feb 12, 2008
    Location:
    Yorkshire, UK
    #5
    Regexp

    Hi,

    Yep, that would work if you're confident that you'll never get text like:

    "Here foo:bar blah blah blah"

    In which case, your script would get a false match of "oo:ba" which clearly isn't a time. If you were to use Satimage OSAX then you could use a regular expression such as:

    Code:
    set theText to "test of extracting the time 19:30 from all of 19 the other text"
    
    set theFoundTimes to find text "[0-9]{2}:[0-9]{2}" in theText with all occurrences and regexp
    Which would match any two digits, a colon then another two digits. You'd probably want to tweak the regular expression to avoid things like 1234:34567 (as an example) if there's a chance they might appear in your text. Writing clever regular expressions is not my strong point!

    Hope that's some help,

    Rob
     
  6. thread starter macrumors newbie

    Joined:
    Mar 13, 2013
    #6
    Thanks superscape (Rob) that great thanks
     

Share This Page