0

I have a string like this:

dfjkldjfdsldfkdslfkd dfkdjd/FR018/HAHDFKDLFDAFHDKFJL/ABCD//NAME/I WANT TO EXTRACT THIS/JJJJ//NAME/blah blah blah

in this string, I want to be able to pull the string I WANT TO EXTRACT THIS. In other words, I want to extract everything that follows /ABCD//NAME/ and before /JJJJ.

how can I write this using regular expressions?

thanks

ctwheels
  • 21,901
  • 9
  • 42
  • 77
pynewbee
  • 665
  • 3
  • 9
  • 19
  • 1
    Are the delimiters constant (`/ABCD//NAME/` and `/JJJJ`)? Or is it based on the number of slashes `/`? What exactly are the rules? This is a **very** simple regex as it stands and you should refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736/learning-regular-expressions). – ctwheels Oct 07 '19 at 19:18
  • Try this: `my ($res) = $str =~ m{/ABCD//NAME/(.*?)/JJJJ}s;` – Håkon Hægland Oct 07 '19 at 19:19
  • @ctwheels yes the delimeters are constant. please help on this. I keep getting errors and cannot figure it out – pynewbee Oct 07 '19 at 21:07
  • @HåkonHægland how would that be written in SAS? – pynewbee Oct 07 '19 at 21:08
  • @pynewbee See my answer for an approach – Håkon Hægland Oct 07 '19 at 21:24

1 Answers1

1

I am not familiar with SAS, but from the documentation it seems like you can do:

re = prxparse('/\/ABCD\/\/NAME\/(.*?)\/(.*?)\/JJJJ/s');
if prxmatch(re, str) then 
    do;
        res = prxposn(re, 1, str);
    end;
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174