I try to match a a group twice in multiline.grep -Pz 'Source: (?<group>.*/).*\n.*\n.*\n.*\k<group>|$'it work except one major problem - it doesn't, \k<group> search for .*/ and not for the same characters that the first occurrence of group matched, which is normal considering that backreferencing is dynamic.Is it possible to get static backreference, meaning that if (?<test>\d\d) match 45 , the next call to group test will always look for 45?I'm not really good at explaining technical terms in english so feel free to yell at me or simply tell me to be more specific.(I use perl grep here but if you have a solution who doesn't use it, go ahead)Edit:To answer the comment below:1: I have a script that bulk move a lot of images files depending of ex if data. It works flawlessly but I want to test if in some cases the source Dir is the same as the output Dir.A sample of a move:[1/1] (TEST - no files are being moved/copied)Source: /disk/media/Camera/IMG_20130611_183722.jpgDate/Time: 2013-06-11 16:37:23Corresponding Tags: Composite:GPSDateTimeDestination (move): ./2013/06-Jun/20130611_163723.IMG_20130611_183722.jpgHere the input and output are not the same so I want the script to not detect anything but if Source: /disk/media/Camera/IMG_20130611_183722.jpgGoes to Destination (move): /disk/media/Camera/20130611_163723.IMG_20130611_183722.jpgI want to highlight the four lines.The purpose is not to retrieve the data for anything else but just to visually identify quickly the detected files.With the regexp up there it always highlight since the second occurrence of the group is dynamic (for grep it doesn't matter that the both are not identical)
Is it possible to get static backreference with grep?
grep;regular expression;perl
OK, I think Ive got it.Your Source: (?<group>.*/).*\n regex is capturing, in the group group,everything after the Source: up through the last / on the line.So, for your example, it is capturing /disk/media/Camera/.To capture the JPEG image filename, you wantSource: .*/(?<group>.*)\nOK, here we go again.I believe that you are getting the static backreference that you want.The problem is that you arent getting the backreferencethat you think youre getting.I think your capture group (and subsequent backreference) is just /.I dont understand why that would happen,except to make a wild guess that the .* is operating in non-greedy mode,so .*/ captures everything up through the first /.Maybe the ? is somehow being interpreted to mean that.I guess what you want might beSource: (?<group>.*/)[^/]*\nwhich forces the .*/ to capture everything up through the last /.