0

I have a url like this

  http://localhost:4970/eagle
&Account=001
&FruitSlad=Apple, Rambutab
 &Fruits=Canada

and I want to extract the text between FruitSlad and the next & and I tried to write a regex for it I tried ((GroupByMultiples)(.$&?)) but it didnt work . Um seeking for a help to extract the text between &FruitSlad and the next &

8
  • 1
    post the expected output.. Commented Oct 24, 2014 at 11:56
  • 1
    you mean this (?<=&FruitSlad=)[^&\n]* or (?<=&FruitSlad=).* Commented Oct 24, 2014 at 11:56
  • expected output is Apple,rambutan Commented Oct 24, 2014 at 11:57
  • @kirov which language, to know wich interpreter and see if you need capture groups or not, etc. Commented Oct 24, 2014 at 11:59
  • its working for Javascript and Python @AvinashRaj thank you Commented Oct 24, 2014 at 11:59

3 Answers 3

1
/FruitSlad=([^&]+)/

See here.

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

Comments

1

In JavaScript you could do the following.

var url = "\
  http://localhost:4970/eagle \
&Account=001 \
&FruitSlad=Apple, Rambutab \
 &Fruits=Canada";

var result = url.split('&')[2].split('=')[1];
console.log(result.trim()); //=> "Apple, Rambutab"

Or if you prefer using regex ...

var result = url.match(/&FruitSlad=([^&]+)/);
if (result)
    console.log(result[1].trim()); //=> "Apple, Rambutab"

Comments

1

The convenient way to get values of query variables in Python 2.x is to use urlparse module:

import urlparse

url = 'http://localhost:4970/eagle?Account=001&FruitSlad=Apple, Rambutab&Fruits=Canada'
vars = urlparse.parse_qs(urlparse.urlparse(url).query)
print vars['FruitSlad'][0]

In Python 3.x use urllib.parse module:

import urllib.parse

url = 'http://localhost:4970/eagle?Account=001&FruitSlad=Apple, Rambutab&Fruits=Canada'
vars = urllib.parse.parse_qs(urllib.parse.urlparse(url).query)
print(vars['FruitSlad'][0])

This module decodes also various encoded characters (%nn), so is more suitable than regex in this case.

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.