2

Tool Used - WebHarvy REgex Flavor - .NET

Looking for an expression to extract the second line (address) from following blocks of text

Company: Acme associates & sons
99122 W. Charleston Blvd., Suite 555, Las Vegas, NV 89135
Phone : (702) 123-4567
Fax : (702) 123-4567
Email : email@example.com

Used the following expression, but it didn't work

(.*)(?=(\n.*){3}$)

Please advise

blackystrat
  • 109
  • 1
  • 5

2 Answers2

2

Note that WebHarvey will return all capturing groups there are defined in the regex pattern. It means you may use any of these

^.*\r?\n(.*)

Or

(?<=^.*\r?\n)(.*)

See the regex demo

You should not blindly test the regexps at the online regex testers. Note that RegexStorm will show a two-line match for ^.*\r?\n(.*) pattern, but look what you get in the Group 1:

enter image description here

That is what WebHarvey will return. See the WebHarvey docs:

WebHarvy will extract only those portion(s) of the main text which matches the group(s) specified in the RegEx string.

Pattern details:

  • ^ - start of string
  • .* - the first line
  • \r?\n - a CRLF or LF line ending
  • (.*) - Line #2 (empty or not, if you need a non-empty line, use .+).

The (?<=...) is a positive lookbehind that requires a first line before the matched second line here, but in WebHarvey, you do not need that.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0

This worked for me:

^.+?[\r\n]+(.+?)[\r\n]

The match is in group 1.

Derek
  • 7,615
  • 5
  • 33
  • 58
  • Hi Derek - it fetched the first and second lines http://regexstorm.net/tester?p=%5e.%2b%3f%5b%5cr%5cn%5d%2b%28.%2b%3f%29%5b%5cr%5cn%5d&i=Company%3a+Jason+Awad+%26+Associates%0d%0a10801+W.+Charleston+Blvd.%2c+Suite+575%2c+Las+Vegas%2c+NV+89135%0d%0aPhone+%3a+%28702%29+732-4141%0d%0aFax+%3a+%28702%29+732-8449%0d%0aEmail+%3a+jason%40jasonawad.com+ – blackystrat Jul 24 '17 at 11:48