[Solved] Pipe Delimited List with numbers into array PHP

Here’s how I went about it for anyone else wondering $SurveyOptions = preg_match_all(‘/(\d+)-([^|]+)/’, $res[‘survey_response_digit_map’], $matches); $finalArray = array_combine($matches[1], $matches[2]); Pretty straight forward. solved Pipe Delimited List with numbers into array PHP

[Solved] regular expression to remove string following [closed]

Instead of gawk, I would recommend using gnu sed for this: $ s=”http://www.example.com/product/9896341.html?utm_source=google&utm_medium=VRM&utm_campaign=N&cid=vizuryjz&utm_content=&color=red&pid=9896341″ $ sed -r ‘s/utm_source=[^&]+//’ <<<“$s” http://www.shopin.net/product/9896341.html?&utm_medium=VRM&utm_campaign=N&cid=vizuryjz&utm_content=&color=red&pid=9896341 This deletes utm_source= followed by anything up to the next ampersand. 1 solved regular expression to remove string following [closed]

[Solved] How to write regex in php for changing content?

Hey that sort of looks like JSON! <?php $file=” string PackageToRun[][] = { {“M16.1″,”M16.1EP1″,”M16.2″,”M17”}, {“Tv16.2″,”Tv17″,”Ta17″,”Ta16.2 MOpenTAS”,”Tv17.1″,”Ta17.1″,”T16.2″,”T16.2c”} }; “; if( preg_match(‘#string PackageToRun\[\]\[\] = ({.*});#is’, $file, $matches)) { $data = json_decode(str_replace(array(‘{‘,’}’), array(‘[‘,’]’), $matches[1])); print_r($data); } Output: Array ( [0] => Array ( [0] => M16.1 [1] => M16.1EP1 [2] => M16.2 [3] => M17 ) [1] => … Read more

[Solved] C++ regular expression

Given that you know the probe part ends with } and the IP part end with a &, it’s probably easiest to just scan for those: sscanf(input, “Ip=%[^&]&probe=%[^}]”, ipt, probe); One minor detail: scanf with either a scanset or a %s conversion needs to have the buffer size specified to have any safety at all. … Read more

[Solved] How to lowercase and replace spaces in bash? [closed]

Requires bash4 (tested with 4.3.48). Assuming you never want a upper case character in the value of the variable output, I would propose the following: typeset -l output output=${input// /_} typeset -l output: Defines the variable to be lowercase only. From man bash: When the variable is assigned a value, all upper-case characters are converted … Read more

[Solved] String parsing, replace new line character

Strings are immutable in Java – operations like replace don’t actually update the original string. You have to use the return value of the substring call, e.g. String updated = str.substring(j,str.indexOf(‘>’,j+1)).replaceAll(“\n”, “#10”); If you want to replace this in the overall string, you can simply concatenate this back into the string: int indexOf = str.indexOf(‘>’,j+1); … Read more

[Solved] Variable inside a REGEX

text = input.replace(/(KEYWORD)\(([^)]+)\)/, “$1 $2”) You realize your example has a space after the keyword yeah? Maybe this instead: text = input.replace(/(KEYWORD)\s*\(([^)]+)\)/, “$1 $2”) 2 solved Variable inside a REGEX

[Solved] javascript regex lookahead why abc match? [closed]

You need to handle new lines and you don’t need global search, because capturing must stop only before first abc appearance, so remove m and g flag and add singleline flag s: const str = `test abc abc`; const result = str.match(/.*?(?=abc)/s); console.log(result); 3 solved javascript regex lookahead why abc match? [closed]

[Solved] Need two regular expressions

You want to learn about character classes: [abc] matches a character that is either an a, a b or a c. [^abc] matches any character that is neither an a, a b nor a c. Together with quantifiers and start- and end-of-string anchors, you’re all set. ^[^X]*$ matches a string of any length that doesn’t … Read more