i need to match & replace with regex each occurence of string like theese:
note: each string can be inside a text OR at the beginning of the text; in both case the regex should match everything from the starting point to the end of the line
Posted by
Someone on March...Posted by:
Someone on March...Posted
March by Someone...Post by
Someone on...by
Someone on....Submitted by:
Someone on...Submitted by
Someone on...
mean just end of line
this is what i have done, but seams to not work always as expected.
/(?:(posted|post|submitted)\s)(?:(by))(?:(.*))\s(.*)|/i
/EDIT:
ok, the problem is i need to match posted|post|submitted by
both on beginning of the string and in the middle of it, and by
only at the beginning of the string otherwise it will match also something like "by the way..."
/((?:^by\s)|(?:.*(?:Post|Submit[t]?)(?:ed)?[\w|\s]*by:?\s?))/im
Group index 1 will be your Posted|Submitted|... and everything to the left.
Try:
/((post(ed)?|submitted)\s)?(by|[a-z]* by):? .*/i
This works for me...
((Post|Posted|Submitted).*)|(by [\w]+ on).*
I ran that against your list on regexpal (www.regexpal.com)
Good luck!
Try this one:
preg_replace ('/((^by[^a-z])|(.*?(posted|post|submitted))).*
?/im', '', $text);