substitution

Bash variable substitution with a regex not working as expected

a 夏天 提交于 2020-08-19 18:00:26
问题 Given a bash variable holding the following string: INPUT="Cookie: cf_clearance=foo; __cfduid=bar;" Why is the substitution ${INPUT/cf_clearance=[^;]*;/} producing the output: Cookie: instead of what I'd expect: Cookie: __cfduid=bar; Testing the same regex in online regex validators confirms that cf_clearance=[^;]*; should match cf_clearance=foo; only, and not the rest of the string. What am I doing wrong here? 回答1: Use the actual regular-expression matching features instead of parameter

Bash variable substitution with a regex not working as expected

倾然丶 夕夏残阳落幕 提交于 2020-08-19 17:57:28
问题 Given a bash variable holding the following string: INPUT="Cookie: cf_clearance=foo; __cfduid=bar;" Why is the substitution ${INPUT/cf_clearance=[^;]*;/} producing the output: Cookie: instead of what I'd expect: Cookie: __cfduid=bar; Testing the same regex in online regex validators confirms that cf_clearance=[^;]*; should match cf_clearance=foo; only, and not the rest of the string. What am I doing wrong here? 回答1: Use the actual regular-expression matching features instead of parameter

Bash variable substitution with a regex not working as expected

不羁岁月 提交于 2020-08-19 17:56:11
问题 Given a bash variable holding the following string: INPUT="Cookie: cf_clearance=foo; __cfduid=bar;" Why is the substitution ${INPUT/cf_clearance=[^;]*;/} producing the output: Cookie: instead of what I'd expect: Cookie: __cfduid=bar; Testing the same regex in online regex validators confirms that cf_clearance=[^;]*; should match cf_clearance=foo; only, and not the rest of the string. What am I doing wrong here? 回答1: Use the actual regular-expression matching features instead of parameter

Replace multiple words in R easily; str_replace_all gives error that two objects are not equal lengths

瘦欲@ 提交于 2020-07-19 06:20:21
问题 I'm trying to use str_replace_all to replace many different values (i.e. "Mod", "M2", "M3", "Interviewer") with one the consistent string (i.e. "Moderator:"). I'm doing this with multiple different categories, and I want avoid having to write each unique value out as there are a lot. So I made a tibble consisting of all the unique values that I want to make standardized and read it in and then pulled out each column (there are 5 but only 2 shown for simplicity) to make them into vectors:

sed command to replace dots

耗尽温柔 提交于 2020-06-27 18:36:12
问题 I have a number of scripts, in which i want to scan a particular type of string, and replace dots in those strings alone. We are replacing our locator strategy from map to something else, so the variables have to be changed from having dots to having underscore In the below, I want to change driver.click(objectMap.getIdentifier(new.dropdown), "DropDown clicking"); TO driver.click(new_dropdown, "DropDown clicking"); So 2 things : remove the text objectMap.getIdentifier Replace the enclosed

Python Regex escape operator \ in substitutions & raw strings

倾然丶 夕夏残阳落幕 提交于 2020-04-26 05:56:09
问题 I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ; puntuation' print('text0=',text) text1 = re.sub(r'(\s+)([;:\.\-])', r'\2', text) text2 = re.sub(r'\s+\.', '\.', text) text3 = re.sub(r'\s+\.', r'\.', text) print('text1=',text1) print('text2=',text2) print('text3=',text3) The theory says: backslash character ('\') to

Python Regex escape operator \ in substitutions & raw strings

◇◆丶佛笑我妖孽 提交于 2020-04-26 05:51:07
问题 I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ; puntuation' print('text0=',text) text1 = re.sub(r'(\s+)([;:\.\-])', r'\2', text) text2 = re.sub(r'\s+\.', '\.', text) text3 = re.sub(r'\s+\.', r'\.', text) print('text1=',text1) print('text2=',text2) print('text3=',text3) The theory says: backslash character ('\') to

SymPy - substitute sybolic entries in a matrix

前提是你 提交于 2020-01-22 00:43:06
问题 I have a python function which generates a sympy.Matrix with symbolic entries. It works effectively like: import sympy as sp M = sp.Matrix([[1,0,2],[0,1,2],[1,2,0]]) def make_symbolic_matrix(M): M_sym = sp.zeros(3) syms = ['a0:3'] for i in xrange(3): for j in xrange(3): if M[i,j] == 1: M_sym = syms[i] elif M[i,j] == 2: M_sym = 1 - syms[i] return M_sym This works just fine. I get a matrix out, which I can use for all the symbolical calculations I need. My issue is that now I want to evaluate

Bad substitution error in ksh [duplicate]

依然范特西╮ 提交于 2020-01-15 09:13:48
问题 This question already has answers here : Cannot debug simple ksh programme (2 answers) Closed 5 years ago . The following KornShell (ksh) script should check if the string is a palindrome. I am using ksh88 , not ksh93 . #!/bin/ksh strtochk="naman" ispalindrome="true" len=${#strtochk} i=0 j=$((${#strtochk} - 1)) halflen=$len/2 print $halflen while ((i < $halflen)) do if [[ ${strtochk:i:1} == ${strtochk:j:1} ]];then (i++) (j--) else ispalindrome="false" break fi done print ispalindrome But I am