Reputation: 1063
I have the string 562865_numbersletterssymbols
If I want to delete, IF EXISTS; the first part (562865_), what should I search?
My guess was ^[^?:(562865_)]+$
to take what was not "562865_" (if existing ?:
) until $ +$
But I discovered that (562865_) searchs every single digit and not the whole string.
How can I find the solution?
Upvotes: 0
Views: 323
Reputation: 1063
Thanks to raina77ow, the easiest way is always the best choice.
$your_var = str_replace('562865_', '', $your_var)
Upvotes: 0
Reputation: 36299
The easiest way that I was able to come up with is this. It will work not only for that name but any others with the same format.
<?php
$string = "562865_numbersletterssymbols";
echo preg_replace("/^\d+_/", "", $string);
Upvotes: 1
Reputation: 903
If you want to stick with regex, try ^[\d]+_(.+)$
the _
splits the string into 2 parts, and you need the second part in parenthesis (.+)
Upvotes: 0