0

I'm using powershell and regex. I'm scraping a web page result to a variable, but I can't seem to extract a generated url from that variable.

this is the content (the actual url varies):

"https://api16-something-c-text.sitename.com/aweme/v2/going/?video_id=v12044gd0666c8ohtdbc77u5ov2cqqd0&

$reg = "([^&]*)&;$" always returns false.

I've been trying -match and Select-String with regex but I'm in need of guidance.

1
  • 1
    Place amp before ;$ Commented Apr 8, 2022 at 21:34

2 Answers 2

1

I suggest using a -replace operation:

$str = '"https://api16-something-c-text.sitename.com/aweme/v2/going/?video_id=v12044gd0666c8ohtdbc77u5ov2cqqd0&' 

$str -replace '^"(.+)&$', '$1'
Sign up to request clarification or add additional context in comments.

Comments

0

It really depends on what format the content is in.

(?<=\&quot;) looks behind "&quot" for (.*?) which any numbers of non-newline characters and then looks ahead for (?=\&amp;) which is "&amp;".

Here's a fair start:

$pattern = "(?<=\&quot;)(.*?)(?=\&amp;)"
$someText = "&quot;https://api16-something-c-text.sitename.com/aweme/v2/going/?video_id=v12044gd0666c8ohtdbc77u5ov2cqqd0&amp;"
$newText = [regex]::match($someText, $pattern)
$newText.Value

Returns:

https://api16-something-c-text.sitename.com/aweme/v2/going/?video_id=v12044gd0666c8ohtdbc77u5ov2cqqd0

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.