0

I am new to Swift programming.

I have a valid regex in javascript, I need the same functionality in swift

str.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=+$/, '');

1 Answer 1

2

Swift 2.3:

let str = "A+B/C===="

let result = str.stringByReplacingOccurrencesOfString("+", withString: "-")
                .stringByReplacingOccurrencesOfString("/", withString: "_")
                .stringByReplacingOccurrencesOfString("\\=+$", withString: "", options: .RegularExpressionSearch)

print(str)
print(result)

Swift 3:

let str = "A+B/C===="

let result = str.replacingOccurrences(of: "+", with: "-")
                .replacingOccurrences(of: "/", with: "_")
                .replacingOccurrences(of: "\\=+$", with: "", options: .regularExpressionSearch)

print(str)
print(result)
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.