Jean-Philippe
Jean-Philippe

Reputation: 173

regular expression: how to find text up to a specific character?

I try to isolate the list of Delphi units used in... a Delphi unit. For this I use the pattern

(uses|Uses|USES)(.*\r\n)(.+\r\n)+

It works quite well in this case:

uses
  SysUtils, Classes, CTLibEnhQuery, CTLibQuery, CTLibDatabase, DB,
  CTMemDataSet, CTDataSet,CTStoredProc, DosCommand, ActnList, CTQuery,
  FlyingOp, Tools, FindFile, Dialogs;

but in this one

uses Variants, HyperStr, Config;
{$R *.dfm}

I also get the {$R *.dfm}. So my question is: how to get the text until the semicolon but not after?
Thanks for your help

Upvotes: 1

Views: 57

Answers (1)

rzymek
rzymek

Reputation: 9291

First off, instead of (uses|Uses|USES), switch your regex matcher into case-insensitive mode. Then do:

uses(([^;]|[\n\r])*)

Regular expression visualization

Group 1 will hold the list you're after.

Upvotes: 2

Related Questions