0

iam trying to get work experience from resume, below code works fine if the text is 2 years 7 months but it does not work with the text 2.7 years.. i just want to get the code if the text would be in both patterns.

 String rx = "\\d+\\s+years?\\s+(?:and\\s*)?\\d+\\s+months?|\\d+\\s+(?:months?|years?)";
    Pattern ptrn = Pattern.compile(rx);
    Matcher m = ptrn.matcher(text);
    while (m.find())
    {System.out.println(m.group(0));}
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
sairam
  • 13
  • 4
  • `(\d+\s+years?\s+(?:and\s*)?\d+\s+months?|\d+\s+(?:months?|years?))|([\d\.]+ year(s)?)` try this, and escape the `\` properly.. hope helps, [regex101 example](https://regex101.com/r/bf83Zt/1) – Bagus Tesa Jan 05 '17 at 07:43
  • Use `"\\d*\\.?\\d+\\s+years?\\s+(?:and\\s*)?\\d+\\s+months?|\\d*\\.?\\d+\\s+(?:months?|years?)"` – Wiktor Stribiżew Jan 05 '17 at 07:47
  • tried.. but showing error Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) – sairam Jan 05 '17 at 07:57

0 Answers0