Perl regex ช่วยจับคู่อักขระใดๆ ยกเว้นช่องว่างต่อท้าย

กำลังมองหาความช่วยเหลือเกี่ยวกับ Perl ฉันไม่เก่งกับ regexes แต่โดยพื้นฐานแล้วฉันต้องการความช่วยเหลือดังนี้:

-strip out the leading blank line
-regex for any value after the directory `/foo/bar/set`, excluding trailing spaces

ผลลัพธ์ที่คาดหวัง:

55
proxy
test.event.done

ทดสอบไฟล์อินพุต:

<leading blank :line here>     
/foo/bar/set/55
/foo/bar/set/proxy
/foo/bar/set/test.event.done

รหัส:

while(my $line=<>) {
    chomp($line);
    if ($line =~ m#foo/bar/set/(not sure what to match here) {
        print "$line\n";
    }
}

person jdamae    schedule 08.04.2011    source แหล่งที่มา
comment
เป็นปัญหาที่คุณเขียนไม่เป็น \S+ หรือไม่?   -  person tchrist    schedule 09.04.2011


คำตอบ (3)


(.*) จับคู่ทุกอย่างในบรรทัดและคุณจะได้รับค่าตั้งแต่ $1

ใช้สิ่งนี้เพื่อทดสอบ regex ของคุณ: http://regexpal.com/

person duedl0r    schedule 08.04.2011
comment
ไม่ อย่าใช้อย่างอื่นเพื่อทดสอบ regex! ใช้ภาษาเพิร์ล - person tchrist; 09.04.2011
comment
อาจจะสำหรับคุณ .. แต่มีคนใหม่ในหัวข้อนี้ - person duedl0r; 09.04.2011

หากอินพุตเป็นเส้นทางไดเร็กทอรีและหากคุณต้องการแยกชื่อไฟล์ คุณสามารถใช้วิธี basename ของโมดูล Perl File::Basename ได้

use File::Basename;
$filename = basename ($dirpath);
person Shalini    schedule 08.04.2011

person    schedule
comment
@euguene - ขอบคุณสำหรับคำตอบของคุณ คุณช่วยบอกฉันหน่อยได้ไหมว่า next if กำลังทำอะไรอยู่? - person jdamae; 09.04.2011
comment
[^\s]มันคืออะไร? นั่นไม่ใช่\Sเหรอ? - person tchrist; 09.04.2011
comment
@tchrist: แน่นอน ถึงเวลาเข้านอนแล้ว - person Eugene Yarmash; 09.04.2011