Using RegEx to get a string

sherbug1015
sherbug1015 used Ask the Experts™
on
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.

docid.jpg
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
m/\/cms\/getfile\/([0-9a-fA-F\-]+)\//
The guid will be in $1 the match variable.

The matched variable might differ with different languages.
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial