Alex
Alex

Reputation: 40395

Regex Query to get string value

I am looking for a regex query that would allow me to retrieve a value from a string here are examples of my string:

home.aspx?StudyID=0020101&aa=72
randompage.aspx?studyid=3023603&aa=40
myconfig.aspx?studyid=0021600&aa=40

I need to get the numerical value of the 'studyid' variable, please note that the name of the page will change so simply doing the substring and counting char spaces didn't work

I unfortunately cannot use request.querystring method as this string is stored in the database and a select statement will be used for running this regex query

Thanks

Upvotes: 0

Views: 159

Answers (3)

user271586
user271586

Reputation:

Use can use parenthesis to capture values in regex.

Therefore, you can match the string to studyid=(\d+) and get the value using $1.

Upvotes: 1

SilentGhost
SilentGhost

Reputation: 319551

/studyid=(\d{7})/i

Upvotes: 2

tloflin
tloflin

Reputation: 4050

/studyid=([^&]*)&/i

The first group will contain the variable.

Upvotes: 0

Related Questions