Reputation: 5260
When resolving git conflicts, I am trying to use regex to capture conflicts from source file, the content is like this:
<<<<<<< HEAD
line1
line2
...
=======
This is my version:
^<<<<<<< HEAD\n\t.+\n\t.+\n\t=======\n\t
Obviously, my version only works for fixed lines because I need to repeat .+\n\t
to match them. But really no idea of how to do this properly? Any tips?
[Update] I am using Perl Compatible Regular Expressions (PCRE) engine from the Boost library.
Upvotes: 1
Views: 3041
Reputation: 626689
You may use
(?sm)^<<<<<<< HEAD.*?\n\t*=======\n*\t*
See the regex demo
Explanation:
(?sm)
- inline modifiers: s
makes the .
match a newline as well as any other character and m
makes the ^
match the line start and $
match the line end^
- start of the line<<<<<<< HEAD
- a literal string <<<<<<< HEAD
.*?
- 0+ any characters, as few as possible, up to the first\n\t*
- LF followed with 0+ tabs=======
- a literal substring\n*\t*
- (not sure you really need it) 0+ LFs followed with 0+ tabs.Upvotes: 3
Reputation: 2031
What language do you use ? The option is allowing the "." to match new line along with ANY char, so that it matches multi line strings.
Adding this require the knowledge of the language in which you code.
Upvotes: 0