我正在使用R进行文本分析。有没有办法使用tm
或stringi
删除所有不在大写字母中的单词?
如果我有这样的东西
Albert Einstein went to the store and saw his friend Nikola Tesla ... + 200 pags
转换为
Albert Einstein Nikola Tesla
祝你好运
答案 0 :(得分:8)
您可以使用简单的正则表达式删除这些单词
gsub("\\b[a-z]+\\s+", "", x)
# [1] "Albert Einstein Nikola Tesla"
这只是寻找单词边界>小写字母>之后的所有字母>之后的所有空格并将其删除
虽然如果你有don't
这样的词,你需要更复杂的正则表达式。像
x <- "if Albert Einstein didn't see his friend Nikola Tesla leavin'"
gsub("\\b[a-z][^ ]*(\\s+)?", "", x)
# [1] "Albert Einstein Nikola Tesla "
答案 1 :(得分:6)
只需使用<?php
session_start();
include "db_connect.php";
$post_id = $_GET['id'];
$reply_content = $_POST['reply_content'];
$reply_creator = $_SESSION['username'];
$date = date('y-m-d H:i:s');
if(isset($_POST['submit_reply'])) {
$sql = "INSERT INTO Replies (post_id, reply_content, reply_creator, reply_date) VALUES ('$post_id', '$reply_content', '$reply_creator', '$date')";
$res = mysqli_query($db, $sql)or die(mysqli_error);
header("Location: home.php");
}else{
echo "Fail.";
}
?>
和正则表达式:
grep