Regex get next line


#1

Hi,

I have couple questions about regex:

Net Cash
5/7/2018
C10660

I want to get 5/7/2018. I tried (?<=Net Cash)((\n.*){1}) which gives me this:
image

how can I start at the line 5/7/2018 and skip all the white space after Net Cash?
Is there a better way to get the data in the next line after finding the match?

Buyer Code:
Code
703-027 01 abc 5523
703-027 01 cde 1423
703-027 01 efg 63.33
703-027 01 aaa 45.70
Version: 10.1

I need to get

703-027 01 abc 5523
703-027 01 cde 1423
703-027 01 efg 63.33
703-027 01 aaa 45.70

I was thinking (?<=(Code$))((\n).*)
but it gives me the white space behind “Code” and 703-027 01 abc 5523 only
It does not always start with 703-027 01, that’s why I need to use Code to find the lines.

  1. I am using regex101.com to test, could you please briefly explain the difference between Full Match, Group 1, Group 2?
    image

Thanks a lot!

Lavina


#2

Hi @lavint

See attached xaml example for reference. It does what you specified in the original post:
ExtractingStrings.zip (2.3 KB)

Knowing how it goes, you will probably have to tune it a bit.
But the gist of the solution is to first split your string using .Split method and only then apply your Regex (if needed).

As to the questions, this code:
(?<=(Code$))((\n).*)
produces those groups because anything you put between () is treated as a group. Try removing those groups like this:
(?<=Code$)\n.*
to see the difference and that they are gone.

Let me know if you have any questions. The code in my example might seem cryptic, but really isn’t and I would be happy to explain more if needed :slight_smile: