私はSASで働いており、この文字列で正しく動作するperl reg exを調べようとしています(srcは文字列、txtは行I ...たいと出力ラインの任意の数があるかもしれません)以下Perl Reg Ex式 - 後にパターンとテキストを抽出する
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;
これはまったく「perl」の質問ではありませんか。私はこれが「魔法の正規表現」の仕事ではなく、むしろ「分割」と同等のものを探していることを示唆しています。 – Sobrique
['。+?(?= \ {2} \ /){2} \ d {4} \ s * \ d {2}(?:: \ d {2}){2 }) '](https://regex101.com/r/Ts05tl/1)? – Gurman
これは正規表現ですが、基本的に文字列の開始/終了を識別する正規表現が必要です。 – TechGuy