Basically, I have the following string:
I want the script to remove only this part:
So that I am left with:
I was provided with the following Applescript which does the job:
set theString to "@junior_cat23, [ID]-[E9B-Z8X-H1V-722]"
do shell script "sed -E -e 's|\\[.*||' -e 's|,||g' -e 's|^[ ]+||' -e 's|[ ]+$||'<<<" & theString's quoted form
But the problem is that it only removes items that are inside the brackets when they are located on the right hand side of the string.
If I have the following string:
It will delete the entire string.
set theString to "[ID]-[E9B-Z8X-H1V-722] this is a test @junior_cat23 @james_cat24"
do shell script "sed -E -e 's|\\[.*||' -e 's|,||g' -e 's|^[ ]+||' -e 's|[ ]+$||'<<<" & theString's quoted form
If I have the following:
It will only return:
set theString to "this is a test [ID]-[E9B-Z8X-H1V-722] @junior_cat23 @james_cat24"
do shell script "sed -E -e 's|\\[.*||' -e 's|,||g' -e 's|^[ ]+||' -e 's|[ ]+$||'<<<" & theString's quoted form
I just want to remove the characters in side of the brackets no matter where they are located in the string (wether they are on the left, right or middle) and keep the others.
I did find a shell script which works in macOS Terminal but I am having issues integrating it into an Applescript
I tried adapting it to my script editor with the “do shell script” command and I get the following error:
Here is the script:
set theString to "this is a test [ID]-[E9B-Z8X-H1V-722] @junior_cat23 @james_cat24"
do shell script "sed -E -e 's/\[[^]]*\]//g' |sed -e 's|-||g' |sed -e 's/,/ /g'" & theString's quoted form
Any help is appreciated. Thanks!