diff --git a/utils.py b/utils.py
index e9a9ffc8f58fa098f895efafaca51d668bb48997..dc6dbf98e259e4ffacce1ea350d07ce35157f945 100644
--- a/utils.py
+++ b/utils.py
@@ -40,9 +40,10 @@ def npmat_truncate_cols(mat, max_cols):
 def get_id_prefix_from_string(s):
     first_illegal_char_index = 0
     for i, c in enumerate(s.replace(' ', '')):
-        first_illegal_char_index = i
         if c not in 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm.-':
             break
+        else:
+            first_illegal_char_index = i + 1
     return s[:first_illegal_char_index]
 
 def stoi(s):