Reputation: 651
How do I remove everything up to first word with at least 2 letters, but include numbers that are touching the start of the 2+ letters? The below code currently removes everything up to the first letter.
$test = "1234 123423-34 b4 3-z a 234 This is a test";
echo preg_replace('/^[^A-Za-z]+/', '', $test);
Should output: This is a test
$test = "1234 123423-34 b4 3-z a 234This is a test";
echo preg_replace('/^[^A-Za-z]+/', '', $test);
Should output: 234This is a test
Upvotes: 0
Views: 33
Reputation: 89547
You can use this pattern:
/^.*?(?=\d*[a-z]\d*[a-z]|$)/i
# ^ ^------ lookahead: followed by a "word" with 2 letters or the end of the string
# '--------- any character + non-greedy quantifier: all characters until
The same in unicode:
/.*?(?=\d*\pL\d*\pL|$)/Au
Upvotes: 3