-1

I have a string and I am trying to use a perl style regex to match the part of the string that occurs after the second occurrence of a particular string.

In this scenario the string is " - " in the following line...

   info - Name non-constant identifiers using lowerCamelCase - lib\util\constants.dart:9:25 - non_constant_identifier_names 

I want to match after the second " - ", start at the 'l' in lib.

I have been trying using positive look behind, but have failed horribly at getting it two match two of the pattern...

Scorb
  • 1,918
  • 7
  • 38
  • 81
  • I am using sublime text which says it uses "perl style regex". Sublime text seems to support look behind. – Scorb Feb 21 '20 at 23:10
  • Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Feb 22 '20 at 00:07

1 Answers1

0

I can't come up with a way to only match after the second occurrence without using variable length look-behind that most regex engines do not support. It is possible and easy to match up to the second occurrence and then capture the rest in a group though.

^(?:.*? - ){2}(.*)$

Example

Diadistis
  • 11,727
  • 1
  • 32
  • 54