Perl Reg Ex Expression - 在它们之后提取模式和文本

时间:2017-11-24 14:55:38

标签: regex perl sas

我在SAS工作,并且一直试图找出一个能正确使用此字符串的perl reg ex (其中src是字符串,txt是我想要的行......并且可能有任意数量的输出行)

src='01/04/2017 03:45:32 Some Comment - abc 05/04/2017 16:32:41 Some other Comment 06/07 at something'
txt='01/04/2017 03:45:32 Some Comment - abc'
txt='05/04/2017 16:32:41 Some other Comment 06/07 at something'

以下是我尝试尝试使用的SAS代码...

data _null_;
  ExpressionID = PRXPARSE('/(\d{2}\/\d{2}\/\d{4}) (\s) (\d{2}\:\d{2}\:\d{2}) /xio');
  text = '01/04/2017 03:45:32 Some Comment - abc 05/04/2017 16:32:41 Some other Comment 06/07 at something';

  start = 1;
  stop = length(text);

  /* Use PRXNEXT to find the first instance of the pattern, */
  /* then use DO WHILE to find all further instances.       */
  /* PRXNEXT changes the start parameter so that searching  */
  /* begins again after the last match.                     */

  call prxnext(ExpressionID, start, stop, text, position, length);      
     do while (position > 0);
        found = substr(text, position, length);
        put found= position= length=;
        call prxnext(ExpressionID, start, stop, text, position, length);
     end;
run;

0 个答案:

没有答案