Hi,
There are some pattern issues i couldnt figure it out myself.
this is working as expected:
final str = "--- spoiler ---\r\n\r\n spoiler content \r\n--- spoiler ---\r\n\r";
Iterable<Match> matches = RegExp(
r"(---( )?(`)?spoiler(`)?( )?---)(.*?)(---( )?(`)?spoiler(`)?( )?---)",
dotAll: true,
multiLine: true,
caseSensitive: false)
.allMatches(str);
matches.forEach((m) => print(m.group(6)));
// output: "spoiler content"
however this is not working. renderText method is not called:
Widget build(BuildContext context) {
return ParsedText(
text: str,
style: TextStyle(color: Colors.black),
parse: [
MatchText(
type: ParsedType.CUSTOM,
pattern:
r"(---( )?(`)?spoiler(`)?( )?---)(.*?)(---( )?(`)?spoiler(`)?( )?---)",
regexOptions: RegexOptions(
dotAll: true,
multiLine: true,
caseSensitive: false,
),
style: TextStyle(
color: Colors.red,
fontSize: 10,
),
renderText: ({String str, String pattern}) {
Map<String, String> map = Map<String, String>();
Match match = RegExp(pattern).firstMatch(str);
map['display'] = "(${match.group(6).trim()})";
map['value'] = match.group(6).trim();
return map;
},
onTap: (url) {
print(url);
}),
],
);
same goes for positive lookbehind
this is working:
final str =
"(lookup: testtest1) content content (lookup: testtest2) content content";
Iterable<Match> matches =
RegExp(r"(?<=\(lookup:)(.*?)(?=\))").allMatches(str);
matches.forEach((m) => print(m.group(0)));
// output: testtest1
// output: testtest2
this is not:
Widget build(BuildContext context) {
return ParsedText(
text: str,
style: TextStyle(color: Colors.black),
parse: [
MatchText(
type: ParsedType.CUSTOM,
pattern:
r"(?<=\(lookup:)(.*?)(?=\))",
style: TextStyle(
color: Colors.red,
fontSize: 10,
),
renderText: ({String str, String pattern}) {
Map<String, String> map = Map<String, String>();
Match match = RegExp(pattern).firstMatch(str);
map['display'] = "(${match.group(2).trim()})";
map['value'] = match.group(2).trim();
return map;
},
onTap: (url) {
print(url);
}),
],
);
im using flutter_parsed_text: ^1.2.3
sdk environment for flutter sdk: ">=2.5.2 <3.0.0"
Hi,
There are some pattern issues i couldnt figure it out myself.
this is working as expected:
however this is not working.
renderTextmethod is not called:same goes for positive lookbehind
this is working:
this is not:
im using
flutter_parsed_text: ^1.2.3sdk environment for flutter
sdk: ">=2.5.2 <3.0.0"