Roger
Roger

Reputation: 597

Get the difference between 2 Strings using regular expressions

Is it possible given 2 strings to get the difference using regular expressions. The length of the examples can vary. For example now it's only Id, Name, and Age. However, it could happen that for other examples they include additional properties. So they could be Id, Name, Age, Occupation, Address, etc. For example I have

example1:

"Id = xcv-sd234-2 \n
Name = joe \n
Age = 32 \n"

example2:

"Id = xcv-sd234-2 \n
Name = Chloe \n
Age = 32 \n
Occupation = driver"

Desired outcome:

"Name = Chloe \n
Occupation = driver"

Upvotes: 0

Views: 45

Answers (1)

Ben Steward
Ben Steward

Reputation: 2407

Split on new line character and compare strings for strict equality (however you do that in Java). Shouldn’t even need regex for that.

Upvotes: 1

Related Questions