r regex Remove all before and up to ":" and keep : code example

Example 1: how do i remove the brackets around a list in python

l = ['a', 2, 'c']
print str(l)[1:-1]
'a', 2, 'c'

Example 2: r substitute string character until :

foo <- "TF_list_to_test10004/Nus_k0.345_t0.1_e0.1.adj:PKMYT1"

# Remove all before and up to ":":
gsub(".*:","",foo)

# Extract everything behind ":":
regmatches(foo,gregexpr("(?<=:).*",foo,perl=TRUE))

Example 3: how to compare a string with its ending in javascript

function solution(str, ending){
  return str.indexOf(ending, str.length - ending.length) !== -1;
}

Example 4: sed only keep string between brackets

echo $str | cut -d "[" -f2 | cut -d "]" -f1

Tags:

Java Example