2

How to capture strings between two words/characters either or both words have multiple occurrences but I want the words both from the first column.

1. A-Hi hello C-0987654321 
2. B-Zzzzzzzzzzzz D-Hi
3. C-I want to go to Europe C- Nexy year D-I wish so 
4. D-Are
5. E-You
6. F-Test
7. G-Test
8. H-Test
9. I-Test
10.J-Test

Desired Capture: C-I want to go to Europe C- Nexy year D-I wish so

I used regex \C-.+\D- but it captures C-0987654321 B-Zzzzzzzzzzzz

I want to capture between lines 3.C- and 4.D-(all from first column) which is “ C-I want to go to Europe C- Nexy year D-I wish so”

Vomit IT - Chunky Mess Style
  • 40,038
  • 27
  • 84
  • 117
  • 1
    So what are the columns though, is `<#>.` column 1 and then the rest after that ``? What does the query you used with the SQL including the regex look like? Or will a solution parsing these results as a string or from text file also work? If you want SQL logic help, it might be best to show example of that including the regex in the select statement. – Vomit IT - Chunky Mess Style Sep 17 '21 at 15:09
  • The numbering represents lines, it’s just like saying line 1 to 10. I want to capture the strings between C- from line#3 first col and D- from line#4 first col. The value is “ C-I want to go to Europe C- Nexy year D-I wish so”. Supposed the entire data is in one file (BLOB) and in textfile like in notedpad++. – Mitchel Araw Sep 17 '21 at 15:27

1 Answers1

2

Using Notepad++


  • Ctrl+F
  • Find what: C-.+D-.+
  • CHECK Match case
  • CHECK Wrap around
  • CHECK Regular expression
  • UNCHECK . matches newline
  • Find Next

Explanation:

C-      # literally C and hyphen
.+      # 1 or more any character but newline
D-      # literally D and hyphen
.+      # 1 or more any character but newline

Screenshot:

enter image description here

Toto
  • 17,001
  • 56
  • 30
  • 41
  • That’s exactly what I want @Toto, let me translate it in toad sql query tomorrow and let you know if it works in sql query…Thank you. – Mitchel Araw Sep 17 '21 at 16:02
  • @MitchelAraw: You're welcome, glad it helps. I don't know the regex flavour in toad sql but if it will work if it is PCRE. – Toto Sep 17 '21 at 16:07
  • Just tried @Toto it works with “ \C-.+\D-.+ “. Thank you. really appreciate it. – Mitchel Araw Sep 17 '21 at 19:20
  • @MitchelAraw: Feel free to mark the answer as accepted, [How to accept an answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – Toto Sep 17 '21 at 19:53
  • Hi @Toto, done. Thank you so much. – Mitchel Araw Sep 18 '21 at 06:25
  • Hi @Toto I have another question but related to my previous one so I don’t need to raise a new question, what’s the regex if I’m going to capture the second occurrence from the multiple occurrences example the Test has 5 occurrences but I want to capture the second only from line 7. Thanks. – Mitchel Araw Sep 19 '21 at 10:38
  • @MitchelAraw: It's too complex to answer in comment. You should ask a new question with sample text and expected result. – Toto Sep 19 '21 at 14:14
  • Sure. Thank you. – Mitchel Araw Sep 19 '21 at 15:37