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

如何用JavaScript从邮件体中精准提取指定字符串DATALINER?

Extracting "DATALINER" from the Log String

Got it, let's fix this extraction issue. The problem with your current code is that after splitting on /, the third element includes everything from DATALINER onwards (like the Msg:... part). Here are a couple of reliable ways to get just DATALINER:

Method 1: Split Twice (Simple & Straightforward)

Since DATALINER is immediately followed by a space and Msg:, we can split the string twice—first on /, then on whitespace—to isolate the target value:

var body = "1180328 101252 RPG0907 710494/PRODUCTION/DATALINER Msg: CI300R 18200 decimal-data error in field (C G S D F).Cause . . . . . : The RPG program CI300R in library OBJECT found a decimal-da";
var jobName = body.split('/')[2].split(' ')[0];
console.log(jobName); // Outputs: DATALINER

This works because splitting on / gives us DATALINER Msg: ... as the third element, then splitting that result on whitespace grabs the first token (exactly what we need).

Method 2: Regular Expression (Robust for Variable Formats)

If you want a more resilient solution (in case the log format has minor variations), use a regex to match the exact pattern around DATALINER:

var body = "1180328 101252 RPG0907 710494/PRODUCTION/DATALINER Msg: CI300R 18200 decimal-data error in field (C G S D F).Cause . . . . . : The RPG program CI300R in library OBJECT found a decimal-da";
const regexPattern = /\/([^\/\s]+)\sMsg:/;
const matchResult = body.match(regexPattern);
var jobName = matchResult ? matchResult[1] : null; // Fallback to null if no match
console.log(jobName); // Outputs: DATALINER

The regex /\/([^\/\s]+)\sMsg:/ breaks down like this:

  • \/: Matches the forward slash before DATALINER
  • ([^\/\s]+): Captures one or more characters that are NOT a slash or whitespace (this is our target DATALINER)
  • \sMsg:: Matches the space and Msg: that come right after it

This ensures we only capture the value we want, even if there are other characters or slight shifts in the log structure.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:59:34