0

I have to find how many numbers in the following String,

'~1~~2~~123~~~~12~~1~~~~' and the output should be 5.

Any help?

  • I'm not sure if you can do this in MySQL. Can you do it on the application layer? – Patashu May 09 '13 at 06:17
  • Use a UDF that implements REGEXP_REPLACE (see http://stackoverflow.com/q/986826/18771) and then replace `\b\d` with `''`. The length difference difference between the original and the replaced string is your number. – Tomalak May 09 '13 at 06:29

2 Answers2

0

MySQL cannot do that directly. You would have to dig into UDF (User defined functions). It would allow you to create a function that returns the number of number substrings in a string.

Dimitar K
  • 794
  • 5
  • 9
0

Regular expression need pattern to match and there no pattern to use regular expression in provided example. You can go here to see regular expression in mysql.

Sandeep Kumar
  • 783
  • 1
  • 5
  • 13