Bash
str='hello world'
echo ${str#*ll}
# o world
echo ${str#*l}
# lo world
echo ${str#*x}
# hello world
Go
package main
import (
"fmt"
"strings"
)
func substrAfter(haystack string, needle string) string {
pos := strings.Index(haystack, needle)
if pos == -1 {
return ""
}
return haystack[pos+len(needle):]
}
func main() {
fmt.Println(substrAfter("hello world", "l")) // lo world
fmt.Println(substrAfter("hello world", "ll")) // o world
fmt.Println(substrAfter("hello world", "x")) //
}
PHP
function substr_after($needle, $haystack) { return substr( strchr($haystack,$needle), strlen($needle) ); }
echo substr_after('ll', 'hello world');
echo substr_after('l', 'hello world');
echo substr_after('x', 'hello world'); // bool(false)
# o world
# lo world
#