0

I have string that looks like this:

link = "<a href=\"http://localhost:5000/confirm/SFMyNTY.g3QAAAACZAAEZGF0YWIAAAsMZAAGc2lnbmVkbgYASDp-jVwB.HqUsytlpKq7h9qEQyjABS1Xv4sgwNFClB-asLYUGfyA\">Potwierdź swoje konto.</a>"

How can I get from token that is after confirm/?

1 Answer 1

1

You can do it with regular expressions like this:

link = "<a href=\"http://localhost:5000/confirm/SFMyNTY.g3QAAAACZAAEZGF0YWIAAAsMZAAGc2lnbmVkbgYASDp-jVwB.HqUsytlpKq7h9qEQyjABS1Xv4sgwNFClB-asLYUGfyA\">Potwierdź swoje konto.</a>"

[[_, token]] = Regex.scan(~r/confirm\/(.*?)"/, link)
IO.puts token

Output:

SFMyNTY.g3QAAAACZAAEZGF0YWIAAAsMZAAGc2lnbmVkbgYASDp-jVwB.HqUsytlpKq7h9qEQyjABS1Xv4sgwNFClB-asLYUGfyA

This will work as long as your HTML structure remains exactly the same. Regex cannot parse arbitrary HTML, as you probably know already.

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.