Reputation: 884
I need a way to remove the first single number in a string, if it exists. This number must be followed by a space in order to be removed.
Examples:
"3 8 GB memory card" should be converted to: "8 GB memory card"
"8GB memory card" should stay the same.
Please advise.
Thanks!
Upvotes: 2
Views: 43
Reputation: 785186
Use this regex to search:
^(\D*)\d+\s+
And replace it by empty string.
This regex matches:
^
- start input\D*
- 0 or more non digits\d+
- 1 or more digits\s+
- 1 or more spacesIn Objective C use this regex:
"^([^0-9]*)[0-9]+ +"
Upvotes: 2