From a line of this format: 41=26; 42=27,5; 43=28; 41=26; 42=27,5; 43=28; , you need to get the values ​​41, 42 and 43.

I tried to do it with the help of options, but if the number is with a comma, for example, 27.5, then the expression does not work further with a comma.

 (...)[0-9][0-9][,.|;]\s(...)[0-9][0-9][,.|;]\s(...)[0-9][0-9][,.|;] 

Tell me, how can I solve the problem?

3 answers 3

For php :

  $str = '41=26; 42=27,5; 43=28;'; preg_match_all('/\d+(?=\=)/', $str, $matches); var_dump($matches[0]); 

    Expression: (\ d +?) =

    Python example:

     >>> re.findall(r'(\d+?)=', '41=26; 42=27,5; 43=28;') ['41', '42', '43'] 

    Expression: \ d +? = (. +?);

     >>> re.findall(r'\d+?=(.+?);', '41=26; 42=27,5; 43=28;') ['26', '27,5', '28'] 

      Java

       String pattern = "41=26; 42=27,5; 43=28;"; pattern = pattern.replaceAll("(^|[^\\d]+)(\\d+)(\\=.*?\\;)", "$2, "); System.out.println(pattern); 

      Decryption:

      (^|[^\\d]+) - grouping $1 - the beginning of a line, or a certain sequence (1 or more) of non-digital characters

      (\\d+) - grouping $2 - a certain sequence (1 or more) of digital characters

      (\\=.*?\\;) - grouping $3 - the sequence begins with a '=' sign, then there is a sequence of any characters (0 or more), the minimum possible to the character ';'


      Result:

      leave the $2 grouping, add ', '


      Conclusion:

      41, 42, 43,