I've got a lot of files (DFM Delphi source files) in which I would like to remove a specific property from all components of a specific class.
Each component definition starts with the word object
or inherited
, followed by:
- Empty space
- The name of the component (alphanumeric)
- Colon
:
- Empty space
- The class of the component (alphanumeric)
Following lines represents properties of the component and are composed by:
- Property name (alphanumeric)
- Empty space
- Equals sign
=
- Empty space
- Property value (alphanumeric)
There also could be other nested components, following the same syntax rules.
The component definition finishes with the end
keyword.
Here is an example:
inherited Test: TTest
OtherProperty = 'Hello'
inherited Component1: TTargetClass
OtherProperty = 100
TargetProperty = True
end
object Component1: TTargetClass
OtherProperty = 'Hello'
end
object Component2: TPanel
OtherProperty = 100
TargetProperty = True
object NestedComponent1: TTargetClass
OtherProperty = 'Hello'
TargetProperty = False
end
end
end
Probably it's not the best way for doing this but I want to accomplish my goal by using a RegEx
in Notepad++
.
The property I want to remove is TargetProperty
and I want to remove the lines who contains it only from components of class TTargetClass
.
inherited Test: TTest
OtherProperty = 'Hello'
inherited Component1: TTargetClass
OtherProperty = 100
end
object Component1: TTargetClass
OtherProperty = 'Hello'
end
object Component2: TPanel
OtherProperty = 100
TargetProperty = True
object NestedComponent1: TTargetClass
OtherProperty = 'Hello'
end
end
end
I've tried the following RegEx
but it matches from the first TTargetClass
to the last end
:
TTargetClass.*(TargetProperty.*\R)end