How to change a comma, by a point, into a decimal number inside a string

4

I was trying to do the following:

String: ajskjnsjs, eeiisois, 10,98 oismsnsjh;

In this case, you just wanted to change the comma of the number by a period , leaving the rest of the string equal. I was using the regexp_replace command from MySQL.

Does anyone have a solution?

    
asked by anonymous 05.04.2017 / 00:32

1 answer

6

PHP:

Use REGEX :

/(?<=\d),+(?=\d)/

Use the preg_replace function of PHP:

preg_replace('/(?<=\d),+(?=\d)/', '.', $string);

Try this here.

MariaDB:

  

Requires support for ? .

Use REGEX :

(?<=[0-9]),+(?=[0-9])

Use the regexp_replace function in MariaDB:

SELECT REGEXP_REPLACE(coluna, '(?<=[0-9]),+(?=[0-9])', '.')

Alternative without ? :

Use REGEX :

([0-9]),([0-9])

Use the regexp_replace function in MariaDB (perhaps MySQL ( UDF )):

SELECT REGEXP_REPLACE(coluna, '([0-9]),([0-9])', '\1.\2')
    
05.04.2017 / 01:22