i want to match “stackover” stored in a variable x in “stackoverflow”,
using perl i can do this as follows;
$x = "stackover";
$y = "stackoverflow";
if ($y =~ /^$x/){
print "success";
}
how do i do this in python,
i cannot have x variable in the regex
reg = re.compile("x") # this will match x instead of matching stackover
thanks
Or
Strictly speaking,
'^'is unnecessary when using.match(), which always seeks a match at the beginning of the string. But I’m leaving it in as a placeholder for other, more complicated regexes.