I have a special case of capturing by regular expression in the SELECT statement.
This is the background: In a poorly designed database, a user might have stored the
amount as the following record:
amount (varchar)
$7,232.05
7,232.05$
7,232.05 only
7,232.05
7232.05
I would like to capture the data with the digits and a period only.
And all the fields should be having same output in this case as:
amount (numeric/decimal/float)
7232.05
7232.05
7232.05
7232.05
7232.05
My ideal query would be something like:
SELECT
amount REGEXP '/[\\d\\.]+/is' AS amount
FROM transactions;
What can be the real alternative to this problem?
It is not a matching for a condition, but the data extraction:
extracting the digits and a period.
By this way, I can even sort the records numerically (low to high, or high to low) with results as expected.
Here were some other issues on regular expressions, a bit different than mine:
- http://www.brainbell.com/tutorials/MySQL/Using_MySQL_Regular_Expressions.htm
- http://www.experts-exchange.com/Database/MySQL/Q_26582728.html
- http://www.phpbuilder.com/board/archive/index.php/t-10334908.html
Thank you for your time in searching for a solution.