我有一根线
"This is a big sentence . ! ? ! but I have to remove the space ."
在这个句子中,我想删除标点符号之前的所有空格,并且应该变成
"This is a big sentence.!?! but I have to remove the space."
我正在尝试使用"\p{Punct}",但无法替换字符串中的内容。
我希望Python只删除字符串中的一些标点符号,假设我想删除除“@”之外的所有标点符号。
import string
remove = dict.fromkeys(map(ord, '\n ' + string.punctuation))
sample = 'The quick brown fox, like, totally jumped, @man!'
sample.translate(remove)
这里的输出是
The quick brown fox like totally jumped man
但我想要的是这样的东西
The quick brown
基本上,我正在寻找一个正则表达式来选择所有标点符号,但URL中的标点符号除外。
本质上,如果我有字符串:
This is a URL: https://test.com/ThisIsAURL !
并删除它应该成为的所有匹配:
This is a URL https://test.com/ThisIsAURL
gsub("[[:punct:]]", "", x)删除所有标点,包括URL中的标点符号。我尝试过使用否定的目光后面选择标点符号后使用的https,但这是不成功的。
在我需要它的情况下,所有的URL都是Twitter链接样式的https://t.co/。它们
我使用下一段代码将文本与单词分开,然后将这些单词插入数据库。问题是逗号也被复制了。如何从逗号跳到复制或任何其他标点符号?
var str = reader1.ReadToEnd();
string[] words = str.Split(' '); //Insert all the song words into words named string
string constring1 = "datasource=localhost;port=3306;username=root;password=abc";
using (var conDataBase1
我在java相对较新。我正在自学如何使用hashmap,我提出了一个问题,如何在一个字符串中找到前三个单词,但问题是去掉字符串中的标点符号--双空格、逗号.当前代码只对一个空格工作,而这个空格是split()函数所在的位置。
public static void main(String[] args) {
String s="a a a b c c d d d d e e e e e";
int max=0;
String maxs="";
List<String> th
我试图删除句子中标点符号之间的空格。为了说明,dataset有许多字符串,如下所示:
"This is a very nice text : ) : ) ! ! ! ."
但我想让他们看起来像这样
"This is a very nice text :):)!!!."
我想通过使用来完成这个任务,但是有人能告诉我如何用Python来完成这个任务吗?我现在有了代码,但是它通过添加额外的空格来实现与我想要的完全相反的功能:
string = re.sub('([.,!?()])', r' \1', string)
我从这些句子中得到了像I want to buy 2 kg of apples!这样的字符串,我想删除某些标点符号,直到现在,这已经足够了: text = strings.ReplaceAll(text, ".", "")
text = strings.ReplaceAll(text, ",", "")
text = strings.ReplaceAll(text, "?", "")
text = strings.ReplaceAll(text, "!", "")
我有一个string var m = "I random don't like confusing random code.",我想删除string m中的子串random的所有实例,返回string parsed并完成删除。
最终结果将是:parsed = "I don't like confusing code."
我该如何在Swift 3.0+中执行此操作?
我使用以下代码删除句子中的标点符号:
import string
translator = str.maketrans({key: None for key in string.punctuation})
s = "I am,a boy"
print(s.translate(translator))
但是,当s= "I am,a男孩“时,输出是"I ama boy",我希望输出为”I am a男孩“(空格b/n "am”& "a")。但是,如果最初有一个空格,如s=中的"I am,a bo
我在读取文件和从文件中删除所有标点符号时遇到了一些问题。下面是我目前所拥有的,我不知道为什么“-”和“*”仍然会出现。
有没有人可以告诉我,我需要如何调整我的replaceAll(),以确保可以删除重复出现的标点符号?
public void analyzeFile(File filepath) {
try {
FileInputStream fStream = new FileInputStream(filepath);
DataInputStream in = new DataInputStream(fStream);
Buffere
我继续问关于如何在否定后的单词中添加前缀"not_“的问题。
在注释中,MrFlick提出了一个使用正则表达式gsub("(?<=(?:\\bnot|n't) )(\\w+)\\b", "not_\\1", x, perl=T)的解决方案。
我想编辑这个正则表达式,以便在"not“或"n't”后面的所有单词中添加_not__前缀,直到有一些标点符号为止。
如果我正在编辑cptn的示例,我想:
x <- "They didn't sell the company, and it went bank
我正在处理回文函数,并找到了一个从字符串中删除标点符号的公式。
var punctuation = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g;
var spaceRE = /\s+/g;
var str = "randomstringwith*&^%"
var testStr = str.replace(punctuation, '').replace(spaceRE, '')
document.write(
我希望在Swift中运行一个快速函数来更改字符串的某些方面。
目标:接受输入字符串UITextField,并将所有标点符号替换为空格(。)或(?)只有标点符号本身在字符串中
问题:我不知道标点符号是什么。有一个UITextField供用户输入。这个textfield也用于其他函数。
示例:输入:你好,你好吗?我做得很好。谢谢。输出:你好,你好吗?我在做fine.Thank你。
测试代码:如果您想在浏览器中进行测试,I也有一个 (JSFiddle for Swift)。
var inputText = "hello, how are you doing? I am okay. Thank
在Java中,修复一些标点符号之后缺失的空格的最佳方法是:
, . ; : ? !
例如:
String example = "This is!just an:example,of a string,that needs?to be fixed.by inserting:a whitespace;after punctuation marks.";
产出应是:
"This is! just an: example, of a string, that needs? to be fixed. by inserting: a whitespace; after punctu
基本上,我有一个具有多个双空格的字符串,如下所示:
"Some text\s\sWhy is there no punctuation\s\s"
我还列出了一个标点符号列表,可以替换双空格,以便输出如下:
puncts = ['.', '?']
# applying some function
# output:
>>> "Some text. Why is there no punctuation?"
我尝试过re.sub(' +', puncts[i], text),但这里的问题是,我不知
所以让我说我有这条绳子
Testing CAP counter and LENGTH li mi TER
我有这个公式
=COUNTA(REGEXEXTRACT(D2; REPT(".* ([А-ЯA-Z]{3,})";COUNTA(SPLIT(REGEXREPLACE(D2;"([А-ЯA-Z]{3,})";"$");"$"))-1)))
预期的行为是,它将计数所有的单词,所有的大写,但3个或更多的字母。
但是,例如,它不计算我的字符串中的"TER“。另外,如果我在字符串中写了"cOUNTER“这样的单词,它就会
这是我的第一个问题!
怎样的模式才能成为最后的"!“在此拆分列表中显示为项吗?
import re
re.split(r'([.?!]) ', 'One sentence. Another one? And the last one!')
我得到:如果我使用['One sentence', '.', 'Another one', '?', 'And the last one!'],或者['One sentence', '.',
我有一个match查询,例如: select * from items where itemdesc MATCH (',') 它返回的数据完全没有意义--包含分号、点等的东西。 但是,like查询返回正确的数据集。 select * from items where itemdesc like ('%,%') 当我使用逗号时,如何正确地返回MATCH查询中的数据-同样的问题仍然存在于撇号中,不确定是否有更多匹配查询不喜欢的字符。