0

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

1
  • What programming language or program are you using? Commented Apr 22, 2010 at 16:00

3 Answers 3

2
/studyid=(\d{7})/i
Sign up to request clarification or add additional context in comments.

3 Comments

I would recommend not using the {7} quantifier. I wouldn't recommend this because he hasn't stated how long a studyID could be. If it is longer then 7 chars then your regex blows up.
@george: if the value is any different than that, then OP needs to provide relevant examples.
Yes generally it is 7 chars, so should be ok Thanks
1

Use can use parenthesis to capture values in regex.

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

Comments

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

The first group will contain the variable.

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.