Reputation: 725
I am trying to find the correct regex to remove all white spaces for different formats of strings like:
A 41 FR 38 ( should become A41FR38)
DGT 4687 P ( should become DGT4687P)
POL 789 EU ( should become POL789EU )
I have tried:
[^\s]+
[^\d]+
and many others, none seem to work, they would only stop at the first space? For example POL 789 EU
would become POL
, and W 85 EU
would become W
https://regex101.com/r/kA1sW4/1
Is this possible?
- EDIT -
I have just discovered that the correct different strings would be HTML outputs. Such as :
.html">W 45 B 1 A 401 L</a>
so I have just tryed: html">([^<]*)
and it outputs :
W 45 B 1 A 401 L
(still with spaces) What should I add to remove the spaces?
demo (still with spaces) https://regex101.com/r/kA1sW4/2
Upvotes: 0
Views: 211
Reputation: 1075
([^\s]+)/g
The g
flag indicates that the regular expression should be tested against all possible matches in a string.
Upvotes: 2
Reputation: 5190
Even simpler simply use str_replace
echo str_replace(' ','','A 41 FR 38');
Results in:
A41FR38
Upvotes: 1