1

I have one string :

function test(){
  var datas = "http://localhost/test/test.html?src=www.123@gmail.com(testing)";
  var spl = datas.match(/[^src=]?\b*/g);
 document.getElementById('demo').innerHTML = spl;
  }
test();
<p id="demo"></p>

I Need ah whole string after the src= string match.i need a answer like www.123@gmail.com(testing) .please help me ...correct my code

prasad
  • 15
  • 3
  • 1
    I wouldn't recommend using a regular expression to do that. But this may help: http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – GOTO 0 Aug 13 '16 at 11:38

2 Answers2

0

You can use regular expression capturing groups and exec() function from JavaScript RegExp prototype.

For example, following code will extract everything after the first occurrence of src= or return null if provided string doesn't match.

function extract(str) {
  var regex = /^(?:.*src=)(.*)$/i;
  return regex.test(str) ? /^(?:.*src=)(.*)$/i.exec(str)[1] : null;
}

document.getElementById('demo').innerHTML = extract('http://localhost/test/test.html?src=www.123@gmail.com(testing)');

Check the explanation of this regular expression and test on different strings at https://regex101.com/r/zW1lK8/1

Jakub Synowiec
  • 5,719
  • 1
  • 29
  • 37
0

here is one way of doing it. you should definitely need to lookup for some online tutorials on using regular expressions.

  var datas = "http://localhost/test/test.html?src=www.123@gmail.com(testing)";
  var m1 = datas.match(/[&?]src=([^&]+)/);
  var spl = "notfound";
  if (m1 && m1.length>1) spl=m1[1];
  document.getElementById('demo').innerHTML = spl;
some1
  • 857
  • 5
  • 11