Notepad++ | 正则表达式查找/替换数值

huangapple go评论72阅读模式
英文:

Notepad++ | Regex Find/replace values

问题

Sure, here's the translated portion:

我有以下格式的数据:

('A','b',*null*,'c')
('D',null,'*e,f*','g')
('1','2','*4,5,6*',null)

我大约有300行类似的数据。
需要将所有斜体的数据更改为'N',这是第三个字段。
所有其余数据都需要保持不变。

我是notepad++的新手。

是否有办法使用正则表达式来实现??

在Excel中尝试了文本分列,但没有成功。

英文:

I have data in the below format

(‘A’,’ b’,*null*,’c’)
(‘D’,null,’*e,f*’,’g’)
(‘1’,’2’,’*4,5,6*’,null)

I have around 300 rows of similar data..
required to change all the data in italics to ‘N’, which is the third field..
all the remaining data need to be as it is.

I am new to notepad++.

Is there a way we can do using regex??

Tried txt to columns in excel, but didn’t work

答案1

得分: 2

  • <kbd>Ctrl</kbd>+<kbd>H</kbd>
  • 查找内容:\((?:&#39;.+?&#39;|null),(?:&#39;.+?&#39;|null),\K(?:&#39;.+?&#39;|null)
  • 替换为:&#39;N&#39;
  • 选中 匹配大小写
  • 选中 循环查找
  • 选择 正则表达式
  • 取消选中 . 匹配换行符
  • <kbd>全部替换</kbd>
英文:
  • <kbd>Ctrl</kbd>+<kbd>H</kbd>
  • Find what: \((?:&#39;.+?&#39;|null),(?:&#39;.+?&#39;|null),\K(?:&#39;.+?&#39;|null)
  • Replace with: &#39;N&#39;
  • TICK Match case
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • <kbd>Replace all</kbd>

Explanation:

\(                  # opening parenthesis
(?:&#39;.+?&#39;|null)      # non capture group, 1 or more any character between single quotes OR literally &quot;null&quot;
,                   # a comma
(?:&#39;.+?&#39;|null)      # non capture group, 1 or more any character between single quotes OR literally &quot;null&quot;
,                   # a comma
\K                  # forget all we have seen until this position
(?:&#39;.+?&#39;|null)      # non capture group, 1 or more any character between single quotes OR literally &quot;null&quot;

Screenshot (before):

Notepad++ | 正则表达式查找/替换数值

Screenshot (after):

Notepad++ | 正则表达式查找/替换数值

huangapple
  • 本文由 发表于 2023年4月13日 16:49:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76003485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定