0

I have as string as "pas" and "with_pas". I want to replace it with blank string. Now I am doing as follows

string.gsub("pas","").gsub("with_pas","") 

In some scenario i get the string as "pas" and in some other with "with_pas".

Is there a better way to do this?

3 Answers 3

3

You can use your current approach, but will need to change the order, otherwise it won't work as expected:

string.gsub("with_pas","").gsub("pas","")
Sign up to request clarification or add additional context in comments.

Comments

2

What about using a regex?

string.gsub(/(with_)?pas/, "")

Comments

0
str.gsub(/pas|with_pas/, '').squeeze

This will remove the words and squeeze will remove the extra space that gsub added.

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.