Skip to main content
deleted 12 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Julia, 93 9090 86 bytes

f(s,p,r,m=match)=(try s=join([match(Regex(join("^$p\$","(.*?)")),s))=m==nothing?s:join([m.captures';[r...""]])end;s)

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r,m=match)=(try s=join([match(Regex(join("^$p\$","(.*?)")),s))=
       m==nothing?s:join([m.captures';[r...""]])end;s)
f (generic function with 21 methodsmethod)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"

Julia, 93 90 bytes

f(s,p,r,m=match(Regex(join("^$p\$","(.*?)")),s))=m==nothing?s:join([m.captures';[r...""]])

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r,m=match(Regex(join("^$p\$","(.*?)")),s))=
       m==nothing?s:join([m.captures';[r...""]])
f (generic function with 2 methods)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"

Julia, 93 90 86 bytes

f(s,p,r)=(try s=join([match(Regex(join("^$p\$","(.*?)")),s).captures';[r...""]])end;s)

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r)=(try s=join([match(Regex(join("^$p\$","(.*?)")),s).captures';[r...""]])end;s)
f (generic function with 1 method)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"
added 4 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Julia, 9393 90 bytes

f(s,p,r,R=Regexm=match(Regex(join("^$p\$","(.*?)")))=ismatch(R,s))=m==nothing?s:join([match(R,s)[m.captures [rcaptures';[r...""]']'""]]):s

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r,R=Regexm=match(Regex(join("^$p\$","(.*?)")),s))=
       ismatch(R,s)m==nothing?s:join([match(R,s)[m.captures [rcaptures';[r...""]']'""]]):s
f (generic function with 2 methods)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"

Julia, 93 bytes

f(s,p,r,R=Regex(join("^$p\$","(.*?)")))=ismatch(R,s)?join([match(R,s).captures [r...""]']'):s

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r,R=Regex(join("^$p\$","(.*?)")))=
       ismatch(R,s)?join([match(R,s).captures [r...""]']'):s
f (generic function with 2 methods)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"

Julia, 93 90 bytes

f(s,p,r,m=match(Regex(join("^$p\$","(.*?)")),s))=m==nothing?s:join([m.captures';[r...""]])

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r,m=match(Regex(join("^$p\$","(.*?)")),s))=
       m==nothing?s:join([m.captures';[r...""]])
f (generic function with 2 methods)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

Julia, 93 bytes

f(s,p,r,R=Regex(join("^$p\$","(.*?)")))=ismatch(R,s)?join([match(R,s).captures [r...""]']'):s

Having to test separately if the match was successful kinda destroys the score. A substitution would require casting to Base.SubstitutionString, which probably isn't worth it...

Test run

julia> f(s,p,r,R=Regex(join("^$p\$","(.*?)")))=
       ismatch(R,s)?join([match(R,s).captures [r...""]']'):s
f (generic function with 2 methods)

julia> f("aacbcbabcccaabcbabcaabbbbca","abaaaccbac","1223334444")
"aacbcbabcccaabcbabcaabbbbca"

julia> f("aacbcbabcccaabcbabcaabbbbcac","abaaaccbac","1223334444")
"1ac2cb2bccc33b3bab4aa4bbbc44"