我想删除所有的符号,除了字符(日本平假名,汉字,罗马字母表),不匹配这个正则表达式。
var reg = RegExp(
r'([\u3040-\u309F]|\u3000|[\u30A1-\u30FC]|[\u4E00-\u9FFF]|[a-zA-Z]|[々〇〻])');我不知道把什么放进去"?“
text=text.replaceAll(?,"");a="「私は、アメリカに行きました。」、'I went to the United States.'"
b="私はアメリカに行きましたI went to the United States"我想把A变成b。
发布于 2022-08-23 16:04:06
您可以使用
String a = "「私は、アメリカに行きました。」、'I went to the United States.'";
a = a.replaceAll(RegExp(r'[^\p{L}\p{M}\p{N}\s]+', unicode: true), '') );此外,如果您只想删除任何标点符号或数学符号,您可以使用
.replaceAll(RegExp(r'[\p{P}\p{S}]+', unicode: true), '')输出:
私はアメリカに行きましたI went to the United States[^\p{L}\p{M}\p{N}\s]+正则表达式匹配一个或多个字符,而不是字母(\p{L})、对话框(\p{M})、数字(\p{N})和空格字符(\s)。
[\p{P}\p{S}]+正则表达式匹配一个或多个标点符号(\p{P})或匹配符号(\p{S})字符。
unicode: true在regex中启用Unicode属性类支持。
发布于 2022-08-23 15:19:20
您可以指定要应用于您的RegEx方法的模式( replaceAll )。
// Creating the regEx/Pattern
var reg = RegExp(r'([\u3040-\u309F]|\u3000|[\u30A1-\u30FC]|[\u4E00-\u9FFF]|[a-zA-Z]|[々〇〻])');
// Applying it to your text.
text=text.replaceAll(reg,"");您可以在这里了解更多:
https://api.flutter.dev/flutter/dart-core/String/replaceAll.html
https://stackoverflow.com/questions/73460924
复制相似问题