• Pete

    (@perthmetro)


    I’m trying to figure out how i can use one or more regular expressions to format a random $ number with 6-7 digits..
    e.g.

    $606782 -> $606 782
    $300000 -> $300 000
    $1237339 -> $1 237 339

Viewing 5 replies - 1 through 5 (of 5 total)
  • Assuming you’re doing this in PHP, you could use number_format() or maybe even money_format()

    Thread Starter Pete

    (@perthmetro)

    Any chance in a bit/lot more help? I’m really bad at regex.

    If you’re using PHP the functions I mentioned do not require regex knowledge.

    Thread Starter Pete

    (@perthmetro)

    I’m using a regex search and replace plugin, but if you have a another solution? I know nothing about php and regex unfortunately. 🙁

    Dion

    (@diondesigns)

    If you really want a regex solution, and you only want to change numbers with 6 or 7 digits, try something like:

    $string = preg_replace(array('(\d\d\d)(\d\d\d)','(\d)(\d\d\d)(\d\d\d)'), array('$1 $2','$1 $2 $3'), $string);

    If you can remove the money ($) character, number_format is a much better solution since it will work with any size number.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘REGEX Regular Expression’ is closed to new replies.