Regular Expression all characters except last one

后端 未结 2 580
无人共我
无人共我 2020-12-14 21:20

This is my string: 50.00.00..00.00

I want to match all . except the last one, so after a replace I end up with 50000000.00

2条回答
  •  萌比男神i
    2020-12-14 21:43

    So you did not specified your regex tools, engine, etc. Well you can do this with e.g. sed (only work if there are always two digits after the last dot and the last dot is always present):

    echo "50.00.00..00.00" | sed 's/\.//;s/\(..\)$/.\1/'
    

    But there are several other ways, e.g. with lookahead regex (if it's supported for you).

    HTH

提交回复
热议问题