is there something akin to regEx in applescript, and if not, what's the alternative?

前端 未结 7 704
感动是毒
感动是毒 2020-12-04 15:54

I need to parse the first 10 chars of a file name to see if they are all digits. The obvious way to do this is fileName =~ m/^\\d{10}/ but I\'m not seeing anything regExy i

7条回答
  •  -上瘾入骨i
    2020-12-04 16:19

    I have an alternative, until I have implemented the character class for the Thompson NFA Algorithm I have made the bare bones of work in AppleScript. If someones interested in looking for parsing very basic regex's with Applescript, then code is posted in CodeExchange at MacScripters, please have a look!

    Here is the solution for figuring out if the ten first characters of a text/string:

     set mstr to "1234567889Abcdefg"
    set isnum to prefixIsOnlyDigits for mstr
    to prefixIsOnlyDigits for aText
        set aProbe to text 1 thru 10 of aText
        set isnum to false
        if not ((offset of "," in aProbe) > 0 or (offset of "." in aProbe) > 0 or (offset of "-" in aProbe) > 0) then
            try
                set aNumber to aProbe as number
                set isnum to true
            end try
        end if
        return isnum
    end prefixIsOnlyDigits
    

提交回复
热议问题