replace

R Ignore character within a Regex string

假如想象 提交于 2021-01-27 21:36:09
问题 I've looked all over for some regex that will cause R to disregard the next character within a regular expression string. For example, given myvector : myvector <- c("abcdef", "ghijkl", "mnopqrs") and a regex string: regexstring <- "[a-z]{3}XXXXXXXXX " which includes some unknown characters XXXXXXXXX, I want to tell R to ignore the final space in the regular expression string itself. After running the following, regexstring <- "[a-z]{3} " sub(regexstring, " ", myvector) gives, "abcdef"

Excel VBA - Delete Single Character from Cell without losing formatting of remainder of cell contents

浪子不回头ぞ 提交于 2021-01-27 18:39:54
问题 I am trying to delete the first occurrence of "<" and ">" in a cell without losing formatting of the remainder of the cell's contents. I have looked in several places here, and other, to no avail. This is what I am trying to do: Say "A1" contains the text: "This is <a> long string with several <occurrences> of a <special> character." In any case, What I am trying to do is remove the ">", and in a perfect world the "<", from the first word which contains them while maintaining the bold

Python: replacing multiple words in a text file from a dictionary

馋奶兔 提交于 2021-01-27 14:40:25
问题 I am having trouble figuring out where I'm going wrong. So I need to randomly replace words and re-write them to the text file, until it no longer makes sense to anyone else. I chose some words just to test it, and have written the following code which is not currently working: # A program to read a file and replace words until it is no longer understandable word_replacement = {'Python':'Silly Snake', 'programming':'snake charming', 'system':'table', 'systems':'tables', 'language':'spell',

How to remove everything except words and emoji from text?

泄露秘密 提交于 2021-01-27 13:53:11
问题 As a part of text classification problem I am trying to clean a text dataset. So far I was removing everything except text. Punctuation, numbers, emoji - everything was removed. Now I am trying to use emoji as features hence I want to retain words as well emoji. First I am searching the emoji in the text and separating them from other words/emoji. This is because each emoji should be treated individually/separately. So I search an emoji and pad it with spaces at both its ends. But I am at

Replacing more than n consecutive values in Pandas DataFrame column

空扰寡人 提交于 2021-01-27 12:48:16
问题 Supposing I have the following DataFrame df df = pd.DataFrame({"a" : [1,2,2,2,2,2,2,2,2,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5], "b" : [3,3,3,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,7,7], "c" : [4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,1,2,2,2,2,2,2,2,2,3,3]}) And I wish to replace number 4's which repeat more than 10 times in a row, in any column (there could be hundreds of columns), with 10 4's and the remainder 5's. So for example, 12 consecutive 4's would be replaced

Excel VBA Replace Text with Two Arrays

て烟熏妆下的殇ゞ 提交于 2021-01-27 12:22:19
问题 I would like to replace the values in column A:A using arrays: Dim aValueNew() As String Dim aValueOld() As String aValueNew = Split("ABC,DEF,GHI", ",") aValueOld = Split("123,456,789", ",") 123 needs to be replaced by ABC, 456 by DEF and so forth. What is the most efficient way of doing this? I am struggling on how to include the Replace function in a loop and your help would be appreciated. Something like: For i = 0 to i = 2 Range("A:A").Replace What:= aValueOld(i), Replacement:=aValueNew(i

How can I find the potential source environment variable for a partial path in PowerShell?

北城以北 提交于 2021-01-27 07:12:43
问题 I want to write a function that converts regular path to path that includes environment variables: For example: C:\Windows\SomePath convert to: %Windir%\SomePath How would I do that and is this possible? Here is what I'm trying to do, but problem is, I need to check the string for all possible variables, is there some more automatic way? such that -replace operator wont be needed function Format-Path { param ( [parameter(Mandatory = $true)] [string] $FilePath ) if (![System.String]:

Python3.x: quickest way to replace characters in very large string

主宰稳场 提交于 2021-01-25 08:19:32
问题 Let's say I have the following extremely large string using Python3.x, several GB in size and +10 billion characters in length: string1 = "XYZYXZZXYZZXYZYXYXZYXZYXZYZYZXY.....YY" Given its length, this already takes +GB to load into RAM. I would like to write a function that will replace every X with A , Y with B , and Z with C . My goal is to make this as quick as possible. Naturally, this should be efficient as well (e.g. there may be some RAM trade-offs I'm not sure about). The most

Python3.x: quickest way to replace characters in very large string

怎甘沉沦 提交于 2021-01-25 08:19:09
问题 Let's say I have the following extremely large string using Python3.x, several GB in size and +10 billion characters in length: string1 = "XYZYXZZXYZZXYZYXYXZYXZYXZYZYZXY.....YY" Given its length, this already takes +GB to load into RAM. I would like to write a function that will replace every X with A , Y with B , and Z with C . My goal is to make this as quick as possible. Naturally, this should be efficient as well (e.g. there may be some RAM trade-offs I'm not sure about). The most

Replace substring in string with range in JavaScript

微笑、不失礼 提交于 2021-01-22 07:01:40
问题 How can I replace a substring of a string given the starting position and the length? I was hoping for something like this: var string = "This is a test string"; string.replace(10, 4, "replacement"); so that string would equal "this is a replacement string" ..but I can't find anything like that. Any help appreciated. 回答1: Like this: var outstr = instr.substr(0,start)+"replacement"+instr.substr(start+length); You can add it to the string's prototype: String.prototype.splice = function(start