0

I need some help with RegEx. I have a URL:

../../temporary/12357704$002cXX$002c302036261/-1;jsessionid=13817F357AB3CD30E0836AA89903A003

or

../../temporary/12337704$002cXX$002c30222261/-1;jsessionid=13817F357AB3CD30E0836AA89903A003

I want always to extract the part between '../../temporary/' and '$002..' so it is 12357704 and 12337704.

3 Answers 3

1

How about this:

result = url.gsub(/^\.\.\/\.\.\/temporary\/(.*?)\$002.*/, "\\1")

This extracts anything after '../../temporary/' and before '$002..'. (Accomplished by .*?, which is "non-greedy").

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

Comments

0

Here's a quick solution:

str.scan(/^..\/..\/temporary\/(\d*)?\$002.*$/).flatten.first

where str is your url.

Comments

0

Something like this would work, but of course you'd need to be sure that the URL matches, or match will return null.

var result = your_url.match(/temporary\/([^$]*)/)[1];

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.