1

I want to match var value between quotes. here's input:

bunch of other text, html tags, css var SECURITYTOKEN = "1354010802-f407561a1503fa33e8e316f058c0f0598ce5adad"; bunch of other text, html tags, css 

result should be 1354010802-f407561a1503fa33e8e316f058c0f0598ce5adad

i was trying something like this: Match m = Regex.Match(input, @"var\sSECURITYTOKEN\s="); but im totally confused.

2

3 Answers 3

3

Your variant finds only the part var SECURITYTOKEN =

use positive lookahead (?=...) and positive lookbehind (?<=...)

String regexPattern = "(?<=var SECURITYTOKEN = \")(.*?)(?=\")"; Match m = Regex.Match(input, regexPattern); 
Sign up to request clarification or add additional context in comments.

Comments

0

Try this regex (?<=")(.*?)(?=")

So it will be something like this

var regexPattern = "(?<=\")(.*?)(?=\")"; Match m = Regex.Match(input, regexPattern); 

Comments

0

This is pretty much the same as og Grand answer but if your input looks like

var foo = "bar"; var SECURITYTOKEN = "1354010802-f407561a1503fa33e8e316f058c0f0598ce5adad"; var tata = "titi"; 

the following will be better :

var regexPattern = "(?<=var SECURITYTOKEN\s*=\s*\")(.*?)(?=\";)"; Match m = Regex.Match(input, regexPattern); 

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.