Remove all characters except the numeric characters from an alphanumeric string.
Example 1:
Input: S = "AA1d23cBB4"
Output: 1234
Explanation: Remove all characters
other than numbers
Example 2:
Input: S = "a1b2c3"
Output: 123
Explanation: Remove all characters
other than numbers
Your task:
Your task is to complete the function string() which takes a single string as input and returns the string. You need not take any input or print anything.
 
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(1)
Constraints:
1 <= |S| <= 10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3
class Solution:
	def removeCharacters(self, S):
		# code here

Solutions:
class Solution:

	def removeCharacters(self, S):
		x = ''
		for char in S:
			if char.isdigit():
				x += char
		return x


class Solution:

	def removeCharacters(self, S):
		a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		result = ''
		for char in S:
			if char in a:
				result += char
		return result


class Solution:

	def removeCharacters(self, S):
		l = [i for i in S if i.isdigit()]
		l = ''.join(l)
		return l


class Solution:

	def removeCharacters(self, S):
		s = []
		for char in S:
			if char.isnumeric():
				s.append(char)
		return ''.join(s)


class Solution:

	def removeCharacters(self, S):
		res = ''
		for i in S:
			if i.isdigit():
				res += i
		return res


class Solution:

	def removeCharacters(self, S):
		str = ''
		for i in S:
			if i.isnumeric():
				str += i
		return str


import re

class Solution:

	def removeCharacters(self, S):
		dig = ''.join(re.findall('\\d', S))
		return dig


class Solution:

	def removeCharacters(self, S):
		s1 = ''
		for i in s:
			if i.isalpha():
				continue
			else:
				s1 += i
		return s1


import re

class Solution:

	def removeCharacters(self, S):
		numeric_chars = re.sub('\\D', '', S)
		return numeric_chars


class Solution:

	def removeCharacters(self, S):
		res = ''
		for i in S:
			ascii = ord(i)
			if ascii >= 48 and ascii <= 57:
				res = res + i
		return res


class Solution:

	def removeCharacters(self, S):
		s = ''
		for i in S:
			if not i.isalpha():
				s += i
		return s


class Solution:

	def removeCharacters(self, S):
		l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
		g = ''
		for i in range(len(S)):
			if s[i] not in l:
				g += s[i]
			else:
				continue
		return g


class Solution:

	def removeCharacters(self, S):
		return ''.join([c for c in S if c.isdigit()])


class Solution:

	def removeCharacters(self, S):
		l = len(S)
		s = ''
		for i in range(l):
			if S[i].isdigit():
				s += S[i]
		return s


class Solution:

	def removeCharacters(self, S):
		i = len(S) - 1
		arr = list(S)
		while i >= 0:
			if not S[i].isnumeric():
				arr.pop(i)
			i -= 1
		return ''.join(arr)


class Solution:

	def removeCharacters(self, S):
		k = ''
		for i in range(len(S)):
			if '0' <= S[i] <= '9':
				k += S[i]
		return k


class Solution:

	def removeCharacters(self, S):
		output = ''
		for i in range(len(S)):
			if S[i].isalpha():
				pass
			else:
				output += s[i]
		return output


class Solution:

	def removeCharacters(self, S):
		temp_list = []
		for i in S:
			if i.isdigit():
				temp_list.append(i)
		return ''.join(temp_list)


class Solution:

	def removeCharacters(self, S):
		s = ''
		for i in S:
			if i.isalpha():
				pass
			else:
				s += i
		return s


class Solution:

	def removeCharacters(self, S):
		v = ''
		for i in S:
			if i in '0123456789':
				v += i
		return v


class Solution:

	def removeCharacters(self, S):
		l = ''
		for i in range(len(S)):
			if S[i] in '0123456789':
				l = l + S[i]
			else:
				continue
		return l


class Solution:

	def removeCharacters(self, S):
		ans = ''
		for i in range(len(S)):
			if S[i].isdigit():
				ans += S[i]
		return ans


class Solution:

	def removeCharacters(self, S):
		num = '0123456789'
		res = ''
		for i in S:
			if i in num:
				res += i
		return res


class Solution:

	def removeCharacters(self, s):
		i = 0
		while i < len(s) - 1:
			if ord(s[i]) >= 48 and ord(s[i]) <= 57:
				i += 1
			else:
				s = s[0:i] + s[i + 1:]
		if s[i].isdigit():
			return s
		return s[0:i]


class Solution:

	def removeCharacters(self, S):
		ans = []
		for i in [*S]:
			if i.isnumeric():
				ans.append(i)
		return ''.join(ans)


class Solution:

	def removeCharacters(self, s):
		new = ''
		for i in s:
			if i.isdigit() == True:
				new += i
		return new


class Solution:

	def removeCharacters(self, S):
		lut = '1234567890'
		res = ''
		for L in S:
			if L in lut:
				res += L
		return res


class Solution:

	def removeCharacters(self, S):
		ans = ''
		for i in range(len(S)):
			if s[i] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
				ans += s[i]
		return ans


class Solution:

	def removeCharacters(self, S):
		st = ''
		for i in s:
			if i.isnumeric():
				st = st + i
		return st


class Solution:

	def removeCharacters(self, S):
		s1 = list(S)
		s2 = []
		for i in s1:
			if i.isnumeric():
				s2.append(i)
		return ''.join(s2)


class Solution:

	def removeCharacters(self, S):
		ans = ''
		for i in S:
			if ord(i) >= ord('0') and ord(i) <= ord('9'):
				ans += i
		return ans


class Solution:

	def removeCharacters(self, S):
		str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
		str1 = ''
		for i in S:
			if i not in str:
				str1 = str1 + i
		return str1


class Solution:

	def removeCharacters(self, S):
		newstr = []
		for i in S:
			if i.isdigit() == 1:
				newstr.append(i)
		ans = ''.join(newstr)
		return ans


class Solution:

	def removeCharacters(self, S):
		res = ''
		for i in S:
			if i >= '0' and i <= '9':
				res += i
		return res


class Solution:

	def removeCharacters(self, S):
		num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		result = ''
		for c in S:
			if c in num:
				result += c
		return result


class Solution:

	def removeCharacters(self, S):
		ans = ''
		for i in S:
			if i >= '0' and i <= '9':
				ans += i
			else:
				continue
		return ans


class Solution:

	def removeCharacters(self, S):
		num = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		s = ''
		for i in S:
			if i in num:
				s += i
		return s


class Solution:

	def removeCharacters(self, S):
		a = ''
		n = [str(i) for i in range(10)]
		for i in s:
			if i in n:
				a += i
		return a


import re

class Solution:

	def removeCharacters(self, S):
		return ''.join([x for x in re.findall('\\d', S)])


class Solution:

	def removeCharacters(self, s):
		string = ''
		for i in s:
			if i.isdigit():
				string += i
			else:
				continue
		return string


class Solution:

	def removeCharacters(self, S):
		a = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
		res = ''
		for i in S:
			if i in a:
				res = res + i
		return res


class Solution:

	def removeCharacters(self, S):
		a = ''.join(filter(str.isdigit, S))
		return a


class Solution:

	def removeCharacters(self, S):
		ec = ''
		n = '0123456789'
		for i in S:
			if i in n:
				ec += i
		return ec


class Solution:

	def removeCharacters(self, s):
		a = ''
		for i in s:
			if i.isdigit():
				a += i
		return a


class Solution:

	def removeCharacters(self, S):
		result = ''
		for char in s:
			if char.isdigit():
				result += char
		return result


class Solution:

	def removeCharacters(self, S):
		c = ''
		n = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
		for i in S:
			if i in n:
				c += i
		return c