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

保留值前提下拆分含文字数字列的GREL实现求助

Step-by-Step Solution for Splitting Text-and-Number Columns in OpenRefine (GREL)

Got it, let's break this down clearly—this is a super common task, and once you know the right regex-based GREL tricks, it's straightforward. We'll split this into two safe steps (no data loss!) as you suggested:

1. Add a New Column for the Number + Trailing Content

First, we'll create a dedicated column to capture everything starting from the first digit in your original column. Here's how:

  • In OpenRefine, select your target column → click Edit column → Add column based on this column
  • Give the new column a name (like "Number & Rest")
  • Paste this GREL expression into the formula box:
    value.match(/\d.*/)[0]
    

What this does:

  • \d matches the first digit in your text
  • .* matches every character that comes after that digit (including more numbers, letters, symbols—whatever follows)
  • match() returns an array of matches; [0] grabs the first (and only, in this case) match to populate the new column

Note: If there's sometimes a space before the first digit (e.g., "Hello World 456"), adjust the regex to /\s*\d.*/ to ignore leading whitespace before the digit.

2. Clean Up the Original Column to Keep Only Leading Text

Now that we've safely stored the numeric portion, let's strip that part out of the original column:

  • Select your original column → click Edit cells → Transform
  • Paste this GREL expression:
    value.replace(/\d.*/, "")
    

What this does:

  • This regex targets the same "first digit + everything after" pattern as before
  • replace() swaps that entire matched segment with an empty string, leaving only the text that came before the first digit

Example to Test With:

If your original cell has ProductABC789X, the new column will get 789X, and the original column will become ProductABC.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:14:34