Remove last two words from a string

RicoStrong

New Member
I am totally new to \[code\]preg_replace\[/code\], but the code below removes the last word from my string:\[code\]preg_replace('/\W\w+\s*(\W*)$/', '$1', $var);\[/code\]I am trying to modify it, so that it removes the last two words.The only thing that I could think of was to replace \[code\]$1\[/code\] with \[code\]$2\[/code\], but this seems to not have any effect at all and was probably just dumb :/The string in question looks kinda like this:\[code\]Lorem ipsum dolor sit amet. Source: LOREM\[/code\]I would like to remove \[code\]Source: LOREM\[/code\]
 
Back
Top