'Regex PRCE exclude string(s)/ignore string(s)
Considering the following code:
TFrmLeistung = class(TFrmStandard)
PanelBottom: TsuiImagePanel;
lbDatum: TLabel;
lbLeistungTyp: TLabel;
**TVirtualKosten = record
KostenLeistung,BetragEH,Pauschal: Currency;
ProzentES: Integer;
end;**
FMengeAutoSet: Boolean;
FMengeAutoSetVal: Integer;
FLstTxtPopupFunctions: TJX2LstTxtPopupFunctions;
FAfterShowCalled: Boolean;
FBAKuerzel : TJX2BAKuerzel;
FPseudoLst : TJX2Leistung
end;
is it possible to select the entire code without the code block between double asterisks with regex?
Basically I am trying to extract the class declration without including the record type.
Also it is possible the multi aquirence of such code and I want to escape all of them in the final results.
Solution 1:[1]
You can use 'lookahead' and 'look behind'.
This RegEx should work: /(?<=^end; \xa)(.*)|(^.*)(?=^.* record)/gsm
However - look-behinds have to be a fixed width, so identifying the end of the record definition is tricky.
This is how it works:
The first alternative captures all text that follows a line starting with end; and having a 'standard' \n line ending. (Note this may not be standard on your platform!)
The second alternative captures all text that is followed by a line that ends with record.
As the look-behind has to be a fixed width the result will be sensitive to how the code is formatted.
You can test this out with your code at regex101 https://regex101.com/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rob Lambden |
