1. import React from 'react';
    2. import styles from './style.module.less';
    3. const highLightString = (keyword, matchString) => {
    4. const highLight = (str) => {
    5. if(!str) {
    6. return '--';
    7. }
    8. const reg = /((\s*)<(\/*)([\sA-Za-z=]*)>(\s*))/g;
    9. const str1 = str.toString().replace(reg, '');
    10. const str2 = str1.replace(/em_full/g, 'span');
    11. const str3 = str2.replace(/em_part/g, 'span');
    12. const str4 = str3.replace(/<span>/g, '<span class=' + styles.matchStr + '>');
    13. return (str4);
    14. };
    15. return (<>
    16. <span
    17. dangerouslySetInnerHTML={
    18. { _html: highLight(matchString) }
    19. }
    20. >
    21. </span>
    22. </>);
    23. };
    24. .matchStr {
    25. color: #b0020b;
    26. }
    27. export default highLightString;