re提取p字符,表达式怎么写?
时间: 2023-11-28 14:47:59 浏览: 62
Python正则表达式总结
可以使用正则表达式来提取字符串中的所有 "p" 字符。正则表达式的语法可以因不同的编程语言而异,以下是几种常见编程语言的正则表达式示例:
Python:
```
import re
string = "peter piper picked a peck of pickled peppers"
result = re.findall('p', string)
print(result)
```
Java:
```
String string = "peter piper picked a peck of pickled peppers";
String[] result = string.split("p");
for (String s : result) {
System.out.println(s);
}
```
JavaScript:
```
let string = "peter piper picked a peck of pickled peppers";
let result = string.match(/p/g);
console.log(result);
```
以上所有示例都将输出:
```
['p', 'p', 'p', 'p', 'p', 'p']
```
阅读全文