Link to home
Start Free TrialLog in
Avatar of sherbug1015
sherbug1015Flag for United States of America

asked on

Using RegEx to get a string

Please see attached image.  On the first line, I need to extract everything between the two / /

Which means the / after getfile and the / after the guid.  I just want to end up with the first guid

Can someone help me with some RegEx to do that.  I have been asked not to use substring.

Thanks.

User generated image
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Further to arnold's post here is some javascript that will do it for you. The pattern is slightly different it does a non-greedy match of everything after the second '/' to the third '/'
<script>
var pattern = /\/cms\/getfile\/(.*?)\//;

$(function() {
  $('#pattern').html(pattern);
  $('button').click(function() {
    var input = $('#url').val();
    var result = input.match(pattern);
    $('#resultbox').html(result[1]);
  });
});
</script>

Open in new window


Working sample here