I need to find all numbers in a string up until (but not including) anything that is not a number. If a number occours later on (after an occourance of a non-number-character) then it shouldn't be included either. I am trying with PHP's command preg_replace
.
This question helped me to write the following pattern:
.+?(?=[^0-9])
Which though doesn't work in:
preg_replace("/.+?(?=[^0-9])/", "", $entry);
where $entry
is my string to search in.
As an example, I could have the following strings:
- 001Aa.bc
- 002a
- 003a4/.
- 004a(4)
- 005 (4).string-d
- 006-34
from which I want to have:
- 001
- 002
- 003
- 004
- 005
- 006
My pattern seems to work in test-sites, like http://gskinner.com/RegExr/. Is my use of the PHP command wrong?