Finding palindrome using regex

前端 未结 3 1699
说谎
说谎 2021-01-12 01:13

This question comes in an attempt to understand one of the answer in : How to check that a string is a palindrome using regular expressions?

Answer

3条回答
  •  温柔的废话
    2021-01-12 02:16

    I made this regEx few days ago. If you use it like this it will give you an array of all palindromes in a certain text. The example is for #JavaScript but you can use the regEx itself in any language to do the job. Works perfect for words to 21 chars or numbers to 21 digits. You can make it more accurate if you need to.


    const palindromeFinder = /\b(\w?)(\w?)(\w?)(\w?)(\w?)(\w?)(\w?)(\w?)(\w?)(\w)\S?\10\9\8\7\6\5\4\3\2\1\b/g;
    
    console.log(inputString.match(palindromeFinder));
    

提交回复
热议问题