Is it possible to create rel=”noindex, nofollow” for a single post if contain bad keywords?

    <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <?php 

        if (is_single()){
            //add more keywords in regex code
            $badWords = array("badwords","badkeyword");
            $string = get_the_content();
            $matches = array();
            $matchFound = '';
            $matchFound = preg_match_all("/\b(" . implode($badWords,"|") . ")\b/i",$string,$matches);
        }

    ?>
    <meta name="robots" content="index,follow <?php echo $matchFound ?>" />
    <?php wp_head() ?>
    </head>