我有一组我需要替换的字符串,但我需要保留字母的大小写.输入字和输出字的长度相同.
例如,如果我需要用"qwer"替换"abcd",那么应该发生以下情况:
"AbcD" translates to "QweR"
"abCd" translates to "qwEr"
Run Code Online (Sandbox Code Playgroud)
等等.
现在我正在使用JavaScript replace,但大写字母在翻译时丢失了.
r = new RegExp( "(" + 'asdf' + ")" , 'gi' );
"oooAsdFoooo".replace(r, "qwer");
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
我正在构建一个django tastypie api,我在ManyToMany关系中添加元素时遇到了问题
示例,models.py
class Picture(models.db):
""" A picture of people"""
people = models.ManyToManyField(Person, related_name='pictures',
help_text="The people in this picture",
)
class Person(models.db):
""" A model to represet a person """
name = models.CharField(max_length=200,
help_text="The name of this person",
)
Run Code Online (Sandbox Code Playgroud)
资源:
class PictureResource(ModelResource):
""" API Resource for the Picture model """
people = fields.ToManyField(PersonResource, 'people', null=True,
related_name="pictures", help_text="The people in this picture",
)
class PersonResource(ModelResource):
""" API Resource for the Person model """
pictures = fields.ToManyField(PictureResource, 'pictures', null=True, …Run Code Online (Sandbox Code Playgroud)