How To Remove Only The Characters Inside Brackets [ ] From A String
One of the reasons you were not getting returned what you wanted is in some cases AppleScript is case insensitive and wrapping the -- Remove Characters code in a considering case block handles some of the issues, but not all. Additionally, since you have numeric characters in both what you want retained and not, then as currently coded it removes all numeric characters.

While your current code could be reworked, I'm not inclined to do that as from both deleted comments and still existing comments you've left out vital information in the OP. That said, I'll assume for the moment that all target strings will have either , [ ... ] or [ ... ] that needs to be removed and the following sed command handles the example value of theName variable in your OP and in the comments.

So whether you have:

set theName to "@junior_cat23, [ID]-[E9B-Z8X-H1V-722]"


Or:

set theName to "@junior_cat23 @james_cat24 [ID]-[E9B-Z8X-H1V-722]"


Then:

do shell script "sed -E -e 's|\\[.*||' -e 's|,||g' -e 's|^[ ]+||' -e 's|[ ]+$||'&lt;&lt;&lt;" &amp; theName's quoted form


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;• Hint: Mouse over and horizontal scroll to see full code.

Returns:

@junior_cat23


Or:

@junior_cat23 @james_cat24


Without any leading/trailing spaces.



Understanding the do shell script and sed commands:


do shell script -- Executes a shell script using the sh shell.
sed -- Stream Editor.


-E -- Interpret regular expressions as extended (modern) regular expressions rather than basic regular expressions (BRE’s). The re_format(7) manual page fully describes both formats.
−e command -- Append the editing commands specified by the command argument to the list of commands.
's|\\[.*||' -- Removes everything from the first [ character to the end of the line.
's|,||g' -- Removes all commas, if they exist.
's|^[ ]+||' -- Removes all leading spaces, if they exist.
's|[ ]+$||' -- Removes all trailing spaces, if they exist.
&lt;&lt;&lt; -- Here Strings - A variant of here documents, the format is: [n]&lt;&lt;&lt; word - The word undergoes brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. Pathname expansion and word splitting are not performed. The result is supplied as a single string, with a newline appended, to the command on its standard input (or file descriptor n if n is specified).

&amp; theName's quoted form -- Appends the single quoted value of the variable theName to the end of the command line of the sed command in the do shell script command so as not to expand any shell special characters in the value of the variable theName, if any exists.