java - Regex to return unique lines when pattern matched -


i parsing log file , trying match error statements. part of line matching "error cs" apply numerous lines duplicates not. there way can not return duplicates. using java flavor of regex..

example: simple regex returns

class1.cs(16,27): error cs0117: 'string' not contain definition 'empty' class1.cs(34,20): error cs0103: name 'thiswworked' not exist in current context class1.cs(16,27): error cs0117: 'string' not contain definition 'empty' class1.cs(34,20): error cs0103: name 'thiswworked' not exist in current context 

would return:

class1.cs(16,27): error cs0117: 'string' not contain definition 'empty' class1.cs(34,20): error cs0103: name 'thiswworked' not exist in current context 

one solution match using regexp , put line data structure set deals removing duplicates you. @ end of parsing print contents of set.

if you're concerned order add map of kind line key , line number value (perhaps checking matching entry before inserting). if sort value you'll list of first instance of given line.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -