Arindam Rudra
Arindam Rudra

Reputation: 624

Extracting the required keywords from text

I have texts like this and the formats are given below.

Salary is 3.6L PA
Salary is 3.5 LPA
Salary is 30,000KPM
Salary is 30,000 KPM
Experience: 3-5years
Experience: 3+ years

Now I need to find Salary like 3.5 or 30,000 and Experience or Minimum experience 3years. If there is space then the experience is working fine but Salary is not working. But if experience "3" and "+" have no place with in it, cant get the result.

Can any one please suggest me the logic to how to get those for both salary and experience.

The only Condition is Salary and the amount will always be in same line and Experience and value will also be in same line.

Thanks in advance.

Upvotes: 1

Views: 154

Answers (1)

Pieter van Ginkel
Pieter van Ginkel

Reputation: 29632

Regular expressions are your friend.

Try the following:

foreach (Match match in Regex.Matches(content, "^(.*?)\\s*(?::| is )\\s*([0-9,.+-]+)(.*)$", RegexOptions.Multiline))
{
    Console.WriteLine("Item1: {0} Item2: {1} Item3: {2}", match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value);
}

Upvotes: 3

Related Questions