How to know if JavaScript string.replace() did anything?

前端 未结 8 1851
盖世英雄少女心
盖世英雄少女心 2021-02-06 21:37

The replace function returns the new string with the replaces, but if there weren\'t any words to replace, then the original string is returned. Is there a way to k

相关标签:
8条回答
  • 2021-02-06 22:24

    As a workaround you can implement your own callback function that will set a flag and do the replacement. The replacement argument of replace can accept functions.

    0 讨论(0)
  • 2021-02-06 22:27

    have a look at string.match() or string.search()

    0 讨论(0)
提交回复
热议问题