如何把所有數字篩選出來的

要篩選出文本中的所有數字,您可以使用多種編程語言中的字符串處理功能。以下是一些常見編程語言中實現這一功能的示例: Python```pythonimport retex...
要篩選出文本中的所有數字,您可以使用多種編程語言中的字符串處理功能。以下是一些常見編程語言中實現這一功能的示例:
Python
```python
import re
text = "我有3個蘋果,2個橙子,以及5個香蕉。"
numbers = re.findall(r'd+', text)
print(numbers) 輸出: ['3', '2', '5']
```
JavaScript
```javascript
let text = "我有3個蘋果,2個橙子,以及5個香蕉。";
let numbers = text.match(/d+/g);
console.log(numbers); // 輸出: ['3', '2', '5']
```
Java
```java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
String text = "我有3個蘋果,2個橙子,以及5個香蕉。";
Pattern pattern = Pattern.compile("d+");
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
本文鏈接:http://xinin56.com/bian/329694.html