0

I have a string that is "FA4.6.0.J7_13443_DATA" and want to parse through boost::regex.

These are some following use-cases are to be take care of:

  1. If first two digit is not "FA" then match failed.
  2. After "FA" string always be a numeric value only.
  3. Matching string only "FA4.6.0", After this extra string have no matching (Means anything will be accepted).
  4. In dotted value there is Max two digit alpha-numeric string only (e.g FA14.66.0, FA4.6a.0, FA4.a6.0, FA4.4.0) and atleast one digit which be always numeric only(e.g. FA4.6.0). if string is "FA4.a.0" then throw an error or not match

Expected Result:

first_data = 4, second_data = 6, third_data = 0

It would be helpful if someone guide me for this problem.

  • 1
    What have you tried? `^FA[0-9]{1,2}[.]([0-9][a-z]|[a-z][0-9]|[0-9])[.][0-9]{1,2}` seems like it should match all your examples. But your explanation of point 4 is rather unclear. – Botje Dec 04 '18 at 08:23
  • Hi Botje, In point 4 I want to say after FA string; there is only one or two digit acceptable (If digit contain single data then it will be only numeric and if digit is contain two data then it will be (2 numeric, 1 numeric and 1 alpha) E.g FA14.66.0 , here after FA there is 14 and after dot 66 will be there which is acceptable but if the digit is greater than 2 and less then 1, then no output and match failed. – jagat singh Dec 04 '18 at 08:33
  • What do you mean by 'if the digit is greater than 2 and less than 1'? Can you provide a more formal specification instead of giving examples and partial rules? – Botje Dec 04 '18 at 08:39
  • For example, the regex I gave above translates to: **the literal string FA**, followed by **one or two digits**, **a dot**, then either [**a digit and a letter**, **a letter and a digit** or **a digit**], followed by **a dot** followed by **one or two digits**. – Botje Dec 04 '18 at 08:41
  • Hi thanks for your comment, now it has work fine with "^[a-zA-Z]{2}[0-9]{1,2}[.][0-9a-zA-Z]{1,2}[.][0-9a-zA-Z]{1,2}[.].*" – jagat singh Dec 04 '18 at 09:24

1 Answers1

0

Now the correct regex is: "^[a-zA-Z]{2}[0-9]{1,2}[.][0-9a-zA-Z]{1,2}[.][0-9a-zA-Z]{1,2}[.].*" and it work fine.