1

How would I decode the following string into normal text from javascript:

s = 'https:\/\/s3.amazonaws.com\/normal-example\/ft_43513_53175ec44096a.mov'

I am currently doing s.replace('\/','/'), but there must be a better way?

1
  • Is that exactly how you're getting it from JavaScript? Commented Mar 27, 2014 at 2:09

1 Answer 1

2

You want to use decode with 'string-escape':

In [1]: s = 'https:\/\/s3.amazonaws.com\/normal-example\/ft_43513_53175ec44096a.mov'.replace('\/', '/')

In [2]: s.decode('string-escape')
Out[2]: 'https://s3.amazonaws.com/normal-example/ft_43513_53175ec44096a.mov'

The official docs on str.decode are here.

The relevant portion is the [The purpose of string-escape is to] produce a string that is suitable as string literal in Python source code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.