1

I would like to use a string variable in my regex when I scan through a document:

urlstring = "example.com"
scanresult = @doc.scan(/variable text in urlstring(.*?)link-text/)

How do I go about doing this?

2 Answers 2

11

#{} are interpreted almost like in "" in regex literal.

is @doc.scan /#{urlstring}(.*?)link-text/ what you want?

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

Comments

1

This should work:

urlstring = "example.com" scanresult = @doc.scan(/variable text in #{urlstring}(.*?)link-text/)

Putting the variable between #{..}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.