punctuation

Python Regex punctuation recognition

你说的曾经没有我的故事 提交于 2019-12-13 09:49:06
问题 I am stumped by this one. I am just learning regular expressions and cannot figure out why this will not return punctuation marks. here is a piece of the text file the regex is parsing: APRIL/NNP is/VBZ the/DT cruellest/JJ month/NN ,/, breeding/VBG Lilacs/NNP out/RB of/IN the/DT dead/JJ land/NN text = open_file.read() grammarList = raw_input("Enter your grammar string: "); tags = grammarList.split("^") tags_pattern = r'\s+'.join(r"([\w\,\:\;\"\-\.]+)/{0}".format(re.escape(tag)) for tag in

Strip Punctuation From String in Python

无人久伴 提交于 2019-12-13 07:02:19
问题 I`m working with documents, and I need to have the words isolated without punctuation. I know how to use string.split(" ") to make each word just the letters, but the punctuation baffles me. 回答1: this is an example using regex, and the result is ['this', 'is', 'a', 'string', 'with', 'punctuation'] s = " ,this ?is a string! with punctuation. " import re pattern = re.compile('\w+') result = pattern.findall(s) print(result) 来源: https://stackoverflow.com/questions/37063500/strip-punctuation-from

Python remove punctuation from a text file

拥有回忆 提交于 2019-12-12 18:27:54
问题 I'm trying to remove a list of punctuation from my text file but I have only one problem with words separated from hyphen. For example, if I have the word "post-trauma" I get "posttrama" conversely I want to get "post" "trauma". My code is: punct=['!', '#', '"', '%', '$', '&', ')', '(', '+', '*', '-'] with open(myFile, "r") as f: text= f.read() remove = '|'.join(REMOVE_LIST) #list of word to remove regex = re.compile(r'('+remove+r')', flags=re.IGNORECASE) out = regex.sub("", text) delta= " "

regexp add space after period but not when period represents a decimal or letter abbreviation?

做~自己de王妃 提交于 2019-12-12 17:39:38
问题 Using php regexp in a simple way, is it possible to modify a string to add a space after periods that follow words but not after a period that is preceded and followed by a number such as 1.00? I also need it to ignore single letter abbreviations such as N.Y. String.Looks like this.With an amount of 1.00 and references N.Y. Needs to be changed to... String. Looks like this. With an amount of 1.00 and references N.Y. This should allow for multiple instances within the string of course... 回答1:

Is there an easy way to handle forms with PHP?

℡╲_俬逩灬. 提交于 2019-12-12 02:45:42
问题 Dealing with forms in PHP has always given me major headaches. Primarily formatting; handling punctuation inside a form input, manipulating strings for database insertions, stripping when retrieving from database, etc. Is there an easy alternative to strip_slashes and all that junk? I don't want a tool like a form wizard that does everything for you - I still would like a high level of customization. What would be nice though is a tool that says "I want this text field to connect to this

How to remove commas from a string in C

江枫思渺然 提交于 2019-12-12 02:23:37
问题 Say I have a string of "10, 5, 3" How can I get rid of the commas so the string is just "10 5 3"? Should I be using strtok? 回答1: char *r, *w; for (w = r = str; *r; r++) { if (*r != ',') { *w++ = *r; } } *w = '\0'; 回答2: Create a new string with the same size (+1 for the terminating character) as your current string, copy each character one by one and replace ',' by ' '. In a for loop you would have something like this : if (old_string[i] == ',') new_string[i] = ' '; else new_string[i] = old

SOLR ignoring comma and other punctuation while searching

荒凉一梦 提交于 2019-12-11 16:58:13
问题 I want to search 100,000 and 100000 only by querying 100000 (or only by querying 100,000). Is it possible to search like that. The purpose to perform this is, that user may add a comma at any place or no comma at all but the strings (100,000 or 100000) should be searched anyway... 回答1: Don't know if this is correct, but maybe you can write some kind of filter factory where numbers are always indexed as numbers formatted with commas and with out commas. Or you can have both the index & query

Remove the punctuation mark with regular expression?

别说谁变了你拦得住时间么 提交于 2019-12-11 09:29:51
问题 I made this function to limit the length of a string in the output, /* limit the lenght of the string */ function limit_length($content, $limit) { # strip all the html tags in the content $output = strip_tags($content); # count the length of the content $length = strlen($output); # check if the length of the content is more than the limit if ($length > $limit) { # limit the length of the content in the output $output = substr($output,0,$limit); $last_space = strrpos($output, ' '); # add dots

Join split words and punctuation with punctuation in the right place

落花浮王杯 提交于 2019-12-11 01:41:43
问题 So I tried using join() after splitting a string into words and punctuation but it joins the string with a space in between the word and punctuation. b = ['Hello', ',', 'who', 'are', 'you', '?'] c = " ".join(b) But that returns: c = 'Hello , who are you ?' and I want: c = 'Hello, who are you?' 回答1: You could join on the punctuation first: def join_punctuation(seq, characters='.,;?!'): characters = set(characters) seq = iter(seq) current = next(seq) for nxt in seq: if nxt in characters:

Remove punctuation but keep hyphenated phrases in R text cleaning

给你一囗甜甜゛ 提交于 2019-12-10 22:14:10
问题 Is there any effective way to remove punctuation in text but keeping hyphenated expressions, such as "accident-prone"? I used the following function to clean my text clean.text = function(x) { # remove rt x = gsub("rt ", "", x) # remove at x = gsub("@\\w+", "", x) x = gsub("[[:punct:]]", "", x) x = gsub("[[:digit:]]", "", x) # remove http x = gsub("http\\w+", "", x) x = gsub("[ |\t]{2,}", "", x) x = gsub("^ ", "", x) x = gsub(" $", "", x) x = str_replace_all(x, "[^[:alnum:][:space:]'-]", " ")