开发者

Python: Regular expression to change image filename [closed]

开发者 https://www.devze.com 2023-01-21 07:23 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学C Closed 12 years ago.

I've got a string looks like this

String a is ACdA(a = %b, ccc= 2r2)

String b is \ewfsd\ss.jpg

Expected outputs:

ACdA(a = %b, ccc= 2r2, b_holder = \ewfsd\ss.jpg)

It adds the string b to the end of string a, that's it! But be careful of the ")"

"b_holder " is hard coded string, it's absolutly same in all cases, won't be changed.

Update: If regular expression is not a best choice here, please suggest a best way to do.


Is

a = "ACdA(a = %b, ccc= 2r2)"
b = "\ewfsd\ss.jpg"
print a[:-1] + ', b_holder = ' + b + ')'

what you had in mind?

Most days of the week, I personally prefer

print '%s, b_holder = %s)' % (a[:-1], b)

I recognize I'm likely in the minority in this particular regard.

There certainly are other implementations, some of them RE-based. I favor the ones above, given what the original questioner has expressed.

0

精彩评论

暂无评论...
验证码 换一张
取 消