In regex_replace action, consider doing line-by-line matching instead of entire file
- 主要語言
- Go
- 星號
- 16
- 分支
- 4
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### TL;DR
As a template developer, I want `^` and `$` to match beginning and end of line, because that's what I'm used to from `grep`. As a template developer I'm probably not aware of how to do RE2 multiline regexes to manually enable this behavior using `(?m:my_regex)`.
cc @sethvargo @pdewilde @verbanicm who have been involved in related conversations.
Upside:
- Users don't have to understand RE2 multiline syntax and semantics to match beginning/end of line
Downside:
- If users want to match a string that spans multiple lines within a file, we have to give them a special mode.
Implementation ideas:
- split each input file on `\n` before doing the regex replace
- add a new mode for users that want to do a search-and-replace that spans multiple lines. Something like:
```
action: `regex_replace`
params:
paths: ['my.txt']
replacements:
mode: 'file_at_a_time' # <---- here we need a new mode
regex: |
my
regex
with
newlines
replace_with: 'whatever'
```
### Detailed design
_No response_
### Alternatives considered
_No response_
### Additional information
_No response_
貢獻指南
研究方向
在程式碼庫中找到 regex_replace action 的實作,該實作可能位於 cmd 或 actions 目錄下。了解它目前如何處理檔案(可能是讀取全部內容)。這項變更涉及依換行字元分割輸入,以便逐行比對,並可能新增一個 mode 參數。尋找 regex_replace 的現有測試,以了解預期行為並新增測試案例。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- go
- 領域
- cli, tooling
- Issue 類型
- 功能
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100