You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

文本文件数据格式转换需求:移除方括号并替换空格为逗号

文本格式转换解决方案

Got it, let's fix that text formatting for you. The goal is to strip out those square brackets and replace spaces between values in each group with commas, while keeping the space between separate groups. Here are two reliable ways to do this:

方法1:Python脚本(精准处理)

This approach uses regular expressions to target each bracket group directly, making it robust even if there are extra spaces inside or outside the brackets.

import re

# Your original input text
original_text = """[-0.00287209 -0.00815337 -0.00322895 -0.00015178] [-0.0038058 -0.01238539 -0.00082072 0.00040815] [-0.00922925 -0.00394288 0.00325778 0.00083047] [-0.01221899 0.01573175 0.00569081 0.00079524] [0.02409868 0.02623219 0.00364268 0.00026268] [ 0.04754814 0.00664801 -0.00204411 -0.00044964] [-0.02286798 -0.02860896 -0.00671971 -0.00086068] [-0.079635 -0.03532551 -0.00594647 -0.00067338] [ 1.13691452e-03 4.88425646e-04 -3.44116748e-05 -1.08364051e-05]"""

def process_group(match):
    # Clean up the content inside each bracket: strip extra spaces, replace spaces with commas
    group_content = match.group(1).strip()
    return group_content.replace(' ', ',')

# Run the replacement
formatted_text = re.sub(r'\[([^\]]+)\]', process_group, original_text)

# Output the result
print(formatted_text)

方法2:快速手动/工具替换(适合非编程场景)

If you don't want to write code, you can use a text editor with regex find-and-replace (like VS Code, Sublime Text):

  1. Find: \[([^\]]+)\]
  2. Replace: $1 (this removes the brackets but keeps the content inside)
  3. Next, handle the spaces: first replace double spaces (from ] [ becoming ) with a unique marker like |, replace all single spaces with commas, then replace | back to a single space.

最终转换结果

After running either method, you'll get exactly the formatted text you need:

-0.00287209,-0.00815337,-0.00322895,-0.00015178 -0.0038058,-0.01238539,-0.00082072,0.00040815 -0.00922925,-0.00394288,0.00325778,0.00083047 -0.01221899,0.01573175,0.00569081,0.00079524 0.02409868,0.02623219,0.00364268,0.00026268 0.04754814,0.00664801,-0.00204411,-0.00044964 -0.02286798,-0.02860896,-0.00671971,-0.00086068 -0.079635,-0.03532551,-0.00594647,-0.00067338 1.13691452e-03,4.88425646e-04,-3.44116748e-05,-1.08364051e-05

内容的提问来源于stack exchange,提问作者singrium

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:25:39