Forum Moderators: coopster
at the moment the above makes this: user1$user2$user3$ look like this: user1user2user3
user.1$user.2$ then that would for some reason output user.1user.2
user1$user2$user3$ but what i want to do is be able to remove everything after the first $ including the $ itself.
$newstring = preg_replace('/^([^\$]+)\$*.*/',$1,$oldstring);
^ string starts with (in THIS context; ^ is a not operator in the class below)
() = store this subpattern in $1
[^\$]+ = subpattern, one or more of any character NOT a $
\$* = followed by zero or more of the the literal $
.* = followed by zero or more of any character
So find anything up to the first $ if it's in the string, store it in $1. If this is followed by a $ and anything else, replace the entire string with $1. This will work whether or not $ is present, that is,
user1
user1$sdfsdf
user1$sdfsd$sdfds$sdfsd
All should store only "user1" in the result.