replace

Regex for a number followed by a word

时光毁灭记忆、已成空白 提交于 2021-02-17 02:48:49
问题 In JavaScript, what would be the regular expression for a number followed by a word? I need to catch the number AND the word and replace them both after some calculation. Here are the conditions in a form of example: 123 dollars => Catch the '123' and the 'dollars'. foo bar 0.2 dollars => 0.2 and dollars foo bar.5 dollar => 5 and dollar (notice the dot before 5) foo bar.5.6 dollar => 5.6 and dollar foo bar.5.6.7 dollar => skip (could be only 0 or 1 dot) foo bar5 dollar => skip foo bar 5dollar

Regex for a number followed by a word

懵懂的女人 提交于 2021-02-17 02:47:45
问题 In JavaScript, what would be the regular expression for a number followed by a word? I need to catch the number AND the word and replace them both after some calculation. Here are the conditions in a form of example: 123 dollars => Catch the '123' and the 'dollars'. foo bar 0.2 dollars => 0.2 and dollars foo bar.5 dollar => 5 and dollar (notice the dot before 5) foo bar.5.6 dollar => 5.6 and dollar foo bar.5.6.7 dollar => skip (could be only 0 or 1 dot) foo bar5 dollar => skip foo bar 5dollar

Replace multiple semicolon to single one in JavaScript

我们两清 提交于 2021-02-17 02:47:13
问题 I try to remove multiple semicolon (;) replace to single semicolon (;) in javascrpt. code: var test ="test1;;test2;;;test3;;;;test4;;;;test5;;;;;test6;;;;;;test7;;;;;;;test8;;;;;;;;test9" test.replace(";;",";") But not get proper output.(must use replace) if any solution I need output like : test1;test2;test3;test4;test5;test6;test7;test8;test9 回答1: Three issues there: When you pass a string into replace as the first argument, only the first occurrence is replaced. To do a global replace, you

Python: Changing values of a nested list

泄露秘密 提交于 2021-02-16 19:45:27
问题 So I'm using a nested list to store some data and I'm having trouble with changing specific values of one of the sublists: if attributes[3] == 'W': self.board[3][3] = 'W' (numbers are placeholders i'm using to test) board is a class variable that is created as follows (I'm trying to create a grid as specified by a user, with their input for column and row sizes making up the first two parts of attributes) self.board = [] rows = [] self.score = [0, 0] for x in range(attributes[0]): rows.append

pandas: Dataframe.replace() with regex

和自甴很熟 提交于 2021-02-16 19:12:21
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

pandas: Dataframe.replace() with regex

心已入冬 提交于 2021-02-16 19:10:33
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

pandas: Dataframe.replace() with regex

房东的猫 提交于 2021-02-16 19:09:48
问题 I have a table which looks like this: df_raw = pd.DataFrame(dict(A = pd.Series(['1.00','-1']), B = pd.Series(['1.0','-45.00','-']))) A B 0 1.00 1.0 1 -1 -45.00 2 NaN - I would like to replace '-' to '0.00' using dataframe.replace() but it struggles because of the negative values, '-1', '-45.00'. How can I ignore the negative values and replace only '-' to '0.00' ? my code: df_raw = df_raw.replace(['-','\*'], ['0.00','0.00'], regex=True).astype(np.float64) error code: ValueError: invalid

Conditional Replace with Visual Studio

拟墨画扇 提交于 2021-02-16 17:58:09
问题 In Visual Studio, I need to substitute a word with another, preserving the first character case. For example I need to subsitute "Bob" with "James" and "bob" with "james" at once, and I must avoid to replace partial matches like "ob" with "james" or "James". This can be done e.g. in Notepad++ with find:"((b)|(B))ob", replace: "(?2j:?3J)ames"; unfortunately this does not work in Visual Studio (I'm using 2015). Is it possible to do this in Visual Studio? Thanks. 回答1: It is not possible with

Find and Replace string in a .txt file with VBscript

霸气de小男生 提交于 2021-02-16 14:21:13
问题 I am trying to figure out how to use vbscript to: 1 - open a .csv file as a .txt file 2 - search for a certain string of text that is located randomly throughout the text 3 - replace that string with a different string. I have found an article that helped me learn how to replace an entire line in a .txt document, but so far have had no luck finding anything about replacing just certain characters within the line. Thanks! Here is the code I am using currently: Const ForReading = 1 Const

Javascript string replace method. Using matches in replacement string

六眼飞鱼酱① 提交于 2021-02-15 07:52:26
问题 I have the following javascript string /Library/Application%20Support/Adobe/Fireworks%20CS6/Commands The numeral in the "CS#" section may change, but I would like to convert the string to the following format keeping in mind that the numeral may change. /Library/Caches/Adobe/TypeSupport/CS6 I know I can do this in several ways, but for the purpose of education I am looking for the best method. I can search with a regular expression using the replace method, but is it possible to use matches