perl - What is this regex substitution "$content =~ s/\n-- \n.*?$//s" actually doing? -


i working through perl code in request tracker 4.0 , have encountered error ticket requestor's message cut off. new perl, have done work regular expressions, i'm having trouble 1 after reading quite bit.

i have narrowed problem down line of code:

$content =~ s/\n-- \n.*?$//s 

i don't understand doing , better explanation.

i understand s/ / matching pattern \n-- \n.*?$ , replacing nothing.

i don't understand .*?$ does. here basic understanding:

  • . character except \n
  • * 0 or more times of preceding character
  • ? 0 or 1 times of preceding character
  • $ end of string

then, understand, final s makes . match new lines

so, roughly, we're replacing text beginning \n-- \n - line of code causing questionable behavior i'd love sorted out if can explain what's going on here.

can explain line doing? removing text after first \n-- \n or there more it?

long winded part / real-life issue (you don't need read answer question)

my exact problem is cutting quoted content @ signature.

so if email customer says:

what going on order abcd?
-- customer

the staff reply says (note loss of customer's signature)

it shipping today

what going on order abcd?

the customer replies

i did not it, did not ship!!!
-- customer

it shipping today

what going on order abcd?

when reply, message cut @ -- kills context.

it shipped today, tracking number 12345

i did not it, did not ship!!!

and leads more work explaining order is, etc.

you're correct: removes last occurrence of "\n-- \n" end. doesn't remove first occurrence due non-greedyness operator ? -- tells regex engine match shortest postsible form of preceding pattern (.*).

what does: in email communication signature separated message body pattern: line consisting of 2 dashes , single trailing space. therefore regex remove beginning signature separator end.

now customer (either manually or email client) add quoted reply of email after signature separator. highly unusual: quoted reply must located before signature modifier. don't know of single email client on purpose, alas there tons of programs out there email (from charset issues on quoting smtp non-conformance can make incredible number of mistakes), wouldn't surprised learn there indeed such clients.

another possibility affectation of client -- signing own name after --. however, suspect not done manually humans seldom insert trailing space after 2 dashes followed line break.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -