0

I'm trying to extract a value from a string. The string looks like this:

<iframe src="/test.php?aed=asd" width="0" height="0" scrolling="no" frameborder="0"></iframe>

The only thing that changes in the link is the value after aed. What would be the easiest way to extract it?

Thanks

1 Answer 1

7

To do this properly you should be using an HTML parsing library, but for a simple extraction, you can use something like:

Regex.Match(s, @"(?<=/test\.php\?aed=)[^""&]+").Value

Means: after seeing the string "/test.php?aed=", match everything up to the next quote or ampersand.

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

4 Comments

That's awesome, works great. Thanks. I'll accept as soon as it's avaible.
[^""&] --- one double quote here is useless.
no it is not, that's is correct representation for double quote inside string literal
@K Ivanov: oh, yes, I need glasses.

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.