[英]How to delete all occurrences (0 or many) of a character between two strings in SAS
[英]Replace all occurrences of a character between two strings
我想使用 Notepad++ 在文本文檔的所有行上用_
字符替換string1
和string2
之間的所有空格。
例子:
string1 this is a first example string2
string1 this is a second example string2
預期結果:
string1_this_is_a_first_example_string2
string1_this_is_a_second_example_string2
我試過這個表達式(?<=string1)(\s*)(?=string2)
,但它沒有用。
您可以使用
查找內容: (?:\G(??^)|string1)(:?(.?string1|string2)?)*.\K\h(?=.*string2)
替換為: _
請參閱正則表達式演示。
注意:
\h
替換為常規空格\G(??^(?<![\s\S]))
,但如果您的預期匹配在一行上,您可能會 go 使用\G(?!^)
。細節
(?:\G(?!^)|string1)
- 前一個匹配的結尾(但不是行首)或string1
(?:(?.string1|string2)?)*?
- 任何字符,0 次或更多次,但盡可能少,即不是開始string1
或string2
字符序列\K
- 丟棄目前匹配的文本\h
- 任何水平空格(?=.*string2)
- 在當前位置右側的任何 0 個或多個除換行符之外的字符之后必須有一個string2
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.