从字符串中提取数字并删除小数点,然后将其添加回字符串中

时间:2018-06-21 16:27:48

标签: javascript jquery

我有一个字符串=“这是测试12.00和15.00”。我的要求是从字符串中删除小数。

我的输出应该是“这是测试12和15”。我尝试过分割字符串并删除小数点并替换它,但是无法正常工作。可以请一些专家对此提供意见。

1 个答案:

答案 0 :(得分:2)

您可以使用下一个正则表达式replace 并使用let str ="this is test 12.00 and 15.00" console.log(str.replace(/\.\d{0,}/g,''))函数删除十进制数字。

希望这会有所帮助:>

[root@optima-ansible ILIAS]# cat testt.yml 
---
- name: test play
  hosts: localhost
  connection: local
  gather_facts: false
  become: yes
  vars:

  tasks:
  - name: simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec
    command: /bin/sleep 60
    async: 45
    poll: 0

  - debug:
      msg: "moving on"
[root@optima-ansible ILIAS]# ansible-playbook testt.yml 

PLAY [test play] *******************************************************************************************************************************************************************************************************

TASK [simulate long running op (15 sec), wait for up to 45 sec, poll every 5 sec] **************************************************************************************************************************************
changed: [localhost]

TASK [debug] ***********************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "moving on"
}

PLAY RECAP *************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0   

[root@optima-ansible ILIAS]# ps -ef | grep sleep
root     10004 10003  0 19:30 ?        00:00:00 /bin/sleep 60
root     10010  5697  0 19:30 pts/0    00:00:00 grep --color=auto sleep
[root@optima-ansible ILIAS]#