Perl regex: Extract values after hypen and before backslash -


i have input data in following format:

abcd-abcd abcd-abcd/efgh-1 abcd-abcd/efgh-1/ijkl-9 abcd-abcd/efgh-1/ijkl-9/mnop-432 abcd-abcd/efgh-1/ijkl-9/mnop-432/qrst-c20-blatt-4 

i want extract below values values above.

abcd abcd,1 abcd,1,9 abcd,1,9,432 abcd,1,9,432,c20-blatt-4 

you can use following regular expression:

(?:\/?[a-z]+-([^\/\n]+)) 

see demo on regex101.

this work if have homogenous input data.

sample perl code:

$str = "abcd-abcd/efgh-1/ijkl-9/mnop-432/qrst-c20-blatt-4"; @myarray = ($str =~ /(?:\/?[a-z]+-([^\/\n]+))/g); print join(",", @myarray) . "\n"; 

output:

abcd,1,9,432,c20-blatt-4 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -