replace

python regex add space whenever a number is adjacent to a non-number

让人想犯罪 __ 提交于 2020-07-20 17:18:08
问题 I am trying to separate non-numbers from numbers in a Python string. Numbers can include floats. Examples Original String Desired String '4x5x6' '4 x 5 x 6' '7.2volt' '7.2 volt' '60BTU' '60 BTU' '20v' '20 v' '4*5' '4 * 5' '24in' '24 in' Here is a very good thread on how to achieve just that in PHP: Regex: Add space if letter is adjacent to a number I would like to manipulate the strings above in Python. Following piece of code works in the first example, but not in the others: new_element = [

VBscript regex replace

孤街醉人 提交于 2020-07-18 21:31:37
问题 I have no idea why this is only applying to the last instance found, not all of them as I would expect. Any help appreciated. Input string: <a href="http://www.scirra.com" target="_blank" rel="nofollow">http://www.scirra.com</a><br /><br /> <a href="http://www.scirra.com" target="_blank" rel="nofollow">http://www.scirra.com</a><br /><hr> Regex: 'SEO scirra links Dim regEx Set regEx = New RegExp ' BB code urls With regEx .Pattern = "<a href=\""http://www.scirra.com([^\]]+)\"" target=\""_blank\

function replace substring returns incorrect answer

本秂侑毒 提交于 2020-07-16 04:24:21
问题 I have a program replacing a substring in a string. The idea is to find the string_to_be_replaced in original_string , then realloc the new_string and connect it to replace_by string. It works for some cases but in some cases like below, it return wrong answer: Input: abc def ghi //orginal string (a blank space) //string to be replaced 1234 //replace by Output: abc1234defT123ghi Expected output: abc1234def1234ghi When I debug it, I saw a wrong character has been filled in the new_string after

Replacing illegal character in fileName

不问归期 提交于 2020-07-14 16:42:55
问题 In Java, I've a File-Name-String. There I want to replace all illegal Characters with '_', but not a-z , 0-9 , - , . and _ I tried following code: But this did not worked! myString = myString.replaceAll("[\\W][^\\.][^-][^_]", "_"); 回答1: You need to replace everything but [a-zA-Z0-9.-] . The ^ within the brackets stands for "NOT". myString = myString.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"); 回答2: If you are looking for options on windows platform then you can try below solution to make use of all

Replacing illegal character in fileName

北城以北 提交于 2020-07-14 16:37:21
问题 In Java, I've a File-Name-String. There I want to replace all illegal Characters with '_', but not a-z , 0-9 , - , . and _ I tried following code: But this did not worked! myString = myString.replaceAll("[\\W][^\\.][^-][^_]", "_"); 回答1: You need to replace everything but [a-zA-Z0-9.-] . The ^ within the brackets stands for "NOT". myString = myString.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"); 回答2: If you are looking for options on windows platform then you can try below solution to make use of all

sed regex to non-greedy replace?

白昼怎懂夜的黑 提交于 2020-07-06 17:39:59
问题 I am aware of another question that is quite similar, but for some reason I'm still having problems. I have a GC log that I'm trying to trim out the Tenured section enclosed in [] . 63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546: [Tenured: 1416K->1065K(1536K), 0.0492621 secs] 1922K->1065K(2112K), 0.0513331 secs] I apply s/\[Tenured:.*\]// And quite expectantly, the result is trimmed greedily through the remainder of the line: 63.544: [GC 63.544: [DefNew: 575K->63K(576K),

sed regex to non-greedy replace?

╄→гoц情女王★ 提交于 2020-07-06 17:37:45
问题 I am aware of another question that is quite similar, but for some reason I'm still having problems. I have a GC log that I'm trying to trim out the Tenured section enclosed in [] . 63.544: [GC 63.544: [DefNew: 575K->63K(576K), 0.0017902 secs]63.546: [Tenured: 1416K->1065K(1536K), 0.0492621 secs] 1922K->1065K(2112K), 0.0513331 secs] I apply s/\[Tenured:.*\]// And quite expectantly, the result is trimmed greedily through the remainder of the line: 63.544: [GC 63.544: [DefNew: 575K->63K(576K),

Replace cell values in each row of pandas column using for loop

风流意气都作罢 提交于 2020-07-06 12:33:29
问题 Please, help me understand my error. I'm trying to change one column in my .csv file. I have .csv file as following: sku,name,code k1,aaa,886 k2,bbb,898 k3,ccc,342 k4,ddd,503 k5,eee,401 I want to replace "k" symbol with the "_" symbol in the "sku" column. I wrote the code: import sys import pandas as pd import numpy as np import datetime df = pd.read_csv('cat0.csv') for r in df['sku']: r1 = r.replace('k', '_') df['sku'] = r1 print (df) But the code inserts the last value in every row of the

How can I replace a string by range?

浪子不回头ぞ 提交于 2020-07-05 06:17:10
问题 I need to replace a string by range Example: string = "this is a string";//I need to replace index 0 to 3 whith another string Ex.:"that" result = "that is a string"; but this need to be dinamically. Cant be replace a fixed word ...need be by range I have tried result = string.replaceAt(0, 'that'); but this replace only the first character and I want the first to third 回答1: function replaceRange(s, start, end, substitute) { return s.substring(0, start) + substitute + s.substring(end); } var

How can I replace a string by range?

人走茶凉 提交于 2020-07-05 06:16:26
问题 I need to replace a string by range Example: string = "this is a string";//I need to replace index 0 to 3 whith another string Ex.:"that" result = "that is a string"; but this need to be dinamically. Cant be replace a fixed word ...need be by range I have tried result = string.replaceAt(0, 'that'); but this replace only the first character and I want the first to third 回答1: function replaceRange(s, start, end, substitute) { return s.substring(0, start) + substitute + s.substring(end); } var