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

PowerShell文本拆分问题:如何从TXT文件提取Brackets版本信息

Extract Specific Version String from TXT File with PowerShell

Hey there! Let's get that "Release 1.11.6" string extracted smoothly. You were on the right track with Where-Object—here's how to finish the code and get exactly what you need:

Option 1: Split by Delimiter

This is straightforward since your text uses # as a clear separator:

Get-Content -Path thisfile.txt | 
    Where-Object { $_ -match '^Brackets#' } | # Filter lines starting with "Brackets#"
    ForEach-Object { ($_ -split '#')[1] } # Split the line by # and grab the 2nd element (index 1)

Breakdown:

  • ^Brackets# uses a regex anchor (^) to ensure we only match lines that start with "Brackets#" (avoids accidental matches elsewhere in the text).
  • Splitting the line with -split '#' turns it into an array like ["Brackets", "Release 1.11.6", "Path-to-Brackets"]—index 1 is your target value.

Option 2: Regex Capture Group

If you prefer a more flexible approach (great if your formatting might vary slightly):

Get-Content -Path thisfile.txt | 
    Where-Object { $_ -match '^Brackets#(.*?)#' } | # Capture text between the first two #s
    ForEach-Object { $matches[1] } # Extract the captured group

Breakdown:

  • The regex ^Brackets#(.*?)# captures everything between the first # after "Brackets" and the next #. The (.*?) is a non-greedy match, so it stops at the first subsequent #.
  • $matches[1] pulls out the content captured by the parentheses.

Quick One-Liner (if only one matching line exists)

If you’re sure there’s only one line starting with "Brackets#" in the file, you can simplify it further:

(Get-Content thisfile.txt | Where-Object { $_ -match '^Brackets#' }) -split '#' | Select-Object -Index 1

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:35:14