-2

I want to get the mid string between SHIP TO: and Account:.

Example Input

SHIP TO: Abc Supply, Inc
123 S. Ramesh
Centralia IL 12345
Account: 234

Expected Output

Abc Supply, Inc
123 S. Ramesh
Centralia IL 12345
Andy A.
  • 1,047
  • 2
  • 12
  • 27
Yugandhar
  • 1
  • 1
  • Please show us some expected output to understand better what do you actually want. Also, did you make some efforts on your own? – AKSingh Jul 14 '21 at 05:15
  • 1
    Does this answer your question? [Regex match everything between two string, spaning multiline](https://stackoverflow.com/questions/16840126/regex-match-everything-between-two-string-spaning-multiline) – 41686d6564 stands w. Palestine Jul 14 '21 at 05:16
  • 1
    Welcome to Stack Overflow! Please take the [tour] and check the [ask] article to familiarize yourself with the rules. – 41686d6564 stands w. Palestine Jul 14 '21 at 05:17
  • Expected output: Abc Supply, Inc 123 S. Ramesh Centralia IL 12345 – Yugandhar Jul 14 '21 at 05:21
  • Please __do your research before__ asking! Searching SO gives [many answers](https://stackoverflow.com/search?q=%5Bregex%5D%20extract%20between%20two%20strings). You will see, how important it is for regex-questions to supply a __language-tag__, because regex syntax varies among them. – hc_dev Jul 14 '21 at 05:40

1 Answers1

0

This question was already asked and answered: Regex match everything between two string, spaning multiline

Use the regex SHIP TO:(.*)Account: with multi-line flag

  • SHIP TO: starts the matching. If not given in input, it wont match!
  • (.*) is the first capture-group (inside parentheses) matching everything .* ... until
  • Account: ends the matching. So if no Account: is present then it wont match!
  • the multiline flag/mode (usually (?m)) can be supplied by the regex-engine / programming-language you use

Test Case

It does match your given example:

SHIP TO: Abc Supply, Inc
123 S. Ramesh
Centralia IL 12345
Account: 234

and extract expected output as group #1:

 Abc Supply, Inc
123 S. Ramesh
Centralia IL 12345

with any character (space) after SHIP TO: and any character (newline) before Account:

See demo on RegexPlanet

hc_dev
  • 5,553
  • 20
  • 27