You can use the do shell script
from within AppleScript to invoke a standard UNIX CLI such as awk
, sed
or grep
. In this case since you merely want to find all occurrences of *-
from the beginning of your string, I'd enlist sed
to do this.
Something like this will remove everything up to the first dash (-
):
set output to do shell script "echo " & quoted form of input & " | sed 's/.*-//'"
Example
Say we had this AppleScript:
set input to "001-10312233_033"
set output to do shell script "echo " & quoted form of input & " | sed 's/.*-//'"
log "input: " & input
log "output: " & output
This sets your example string as the variable input
. The 2nd line then takes the variable input
and echoes the variable to the sed
command | sed 's/.*-//'
. This will strip everything (.*
) up to the first dash, (-
), encountered, and replaces it with nothing (//)
in sed
.
The last 2 commands with the log
merely echo the 2 variables, input
& output
.
Here's the whole thing in action:
$ cat regex.sh
#!/bin/bash
osascript <<END
set input to "001-10312233_033"
set output to do shell script "echo " & quoted form of input & " | sed 's/.*-//'"
log "input: " & input
log "output: " & output
END
Make sure the script regex.sh
is executable:
$ chmod + regex.sh
And we run it like this:
$ ./regex.sh
input: 001-10312233_033
output: 10312233_033