Perl to Python regex help needed -
i new python regex, , did not find enough info how in python
perl:
my $a="some pattern"; $b="some other pattern"; $str =~ s/\s*$a\s+\-\-\>\s+$b/ $b/;
$a , $b change, , specific strings need substituted. idea how in python?
import re = "some pattern" b = "some other pattern" # create regular expression. '-' , '>' don't need escaping pattern = re.compile(r'\s*' + + '\s+-->\s+' + b) # 'str' poor variable name in python; hides built-in result = pattern.sub(' ' + b, result)
although don't know how fail find enough information, assuming understand how regexes work. did read documentation?
there no equivalent perl's /o flag; if want compile regular expression once , re-use it, then... that; play scope of pattern
re.compile
line run once.
Comments
Post a Comment