我想提取在以下文本中"CREATE INDEX"和")"之间出现的所有文本

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

I want to extract all occurring text between "CREATE INDEX" and ")" on the following text

问题

我要提取以下文本:

CREATE INDEX "SCHEMA"."INDEX_NAME1" ON "SCHEMA"."TABNAME1" 
    ("COLX" ASC)

CREATE INDEX "SCHEMA"."INDEX_NAME2" ON "SCHEMA"."TABNAME2"  
    ("COL1" ASC,
     "COL2" ASC)

然后,您可以将这段提取的文本复制到另一个文本文件中或进行其他必要的操作。

英文:

I have a text looking like this. But there are thousands of lines to the text. I want to extract text from this and only get the index data.

CREATE INDEX "SCHEMA"."INDEX_NAME1" ON "SCHEMA"."TABNAME1" 
		("COLX" ASC)
		
		COMPRESS NO 
		INCLUDE NULL KEYS ALLOW REVERSE SCANS;

-- DDL Statements for Indexes on Table "CBLOSUAT"."KCR_PRODUCT"

SET SYSIBM.NLS_STRING_UNITS = 'SYSTEM';

CREATE INDEX "SCHEMA"."INDEX_NAME2" ON "SCHEMA"."TABNAME2"  
		("COL1" ASC,
         "COL2" ASC)
		
		COMPRESS NO 
		INCLUDE NULL KEYS ALLOW REVERSE SCANS;

I want something like

CREATE INDEX "SCHEMA"."INDEX_NAME1" ON "SCHEMA"."TABNAME1" 
		("COLX" ASC)

CREATE INDEX "SCHEMA"."INDEX_NAME2" ON "SCHEMA"."TABNAME2"  
		("COL1" ASC,
         "COL2" ASC)

I am getting the text by using "CREATE INDEX[^;]+;" in search mode but now I want to select all of the code and copy it to another text file or create a new text file or delete the rest of the code while keeping what I want.

答案1

得分: 1

  • <kbd>Ctrl</kbd>+<kbd>H</kbd>
  • 查找内容:^\h*CREATE INDEX.+?\(.+?\)\R(*SKIP)(*FAIL)|.
  • 替换为:LEAVE EMPTY
  • TICK 环绕
  • SELECT 正则表达式
  • TICK . 匹配换行
  • <kbd>全部替换</kbd>
英文:
  • <kbd>Ctrl</kbd>+<kbd>H</kbd>
  • Find what: ^\h*CREATE INDEX.+?\(.+?\)\R(*SKIP)(*FAIL)|.
  • Replace with: LEAVE EMPTY
  • TICK Wrap around
  • SELECT Regular expression
  • TICK . matches newline
  • <kbd>Replace all</kbd>

Explanation:

^               # beginning of line
\h*             # 0 or more horizontal spaces
CREATE INDEX    # literally
.+?             # 1 or more any character, not greedy
\(              # opening parenthesis
.+?             # 1 or more any character, not greedy
\)              # closing parenthesis
\R              # any kind of linebreak
(*SKIP)         # forget this match
(*FAIL)         # and considere the match has failed
  |               # OR
.               # any character

Screenshot (before):

我想提取在以下文本中"CREATE INDEX"和")"之间出现的所有文本

Screenshot (after):

我想提取在以下文本中"CREATE INDEX"和")"之间出现的所有文本

答案2

得分: 0

我首先在正则搜索模式中使用了"CREATE INDEX[^;]+\Q)\E"来找到答案,然后从Notepad++提供的选项中标记并复制它。

标记和复制的步骤

英文:

I found the answer by the way. I first used "CREATE INDEX[^;]+\Q)\E" in the regex search mode. Then marked it and copy it from the options provided by the notepad++

Steps to mark and copy

huangapple
  • 本文由 发表于 2023年4月6日 20:32:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949556.html
匿名

发表评论

匿名网友

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

确定