Skip to content

Commit

Permalink
Upgrade regex + italic parser (#42)
Browse files Browse the repository at this point in the history
* improved phone pattern: https://regexr.com/3aevr

* Url pattern: https://uibakery.io/regex-library/url

* italic pattern :D

* added Italics parser

* Undo changes
  • Loading branch information
NickStijger authored Sep 21, 2023
1 parent 5c755ef commit 61e3c2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,17 @@ class BoldParser extends ParserType {
};
}
}

class ItalicParser extends ParserType {
ItalicParser(
{Function(Matched)? onTap,
TextStyle? style,
String pattern = RTUtils.italicPattern})
: super(style: style, onTap: onTap, pattern: pattern) {
renderText = ({String? str}) {
return Matched(
display: str?.substring(1, str.length - 1),
value: str?.substring(1, str.length - 1));
};
}
}
3 changes: 2 additions & 1 deletion lib/src/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ class RTUtils {

/// URL Regex - A predefined type for handling URL matching
static const urlPattern =
r'[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:_\+.~#?&//=]*)';
r'''[(http(s)?):\/\/(www\.)?a-zA-Z0-9!@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9!@:%_\+.~#?&//=]*)''';

/// Phone Regex - A predefined type for handling phone matching
static const phonePattern =
r'(\+?( |-|\.)?\d{1,2}( |-|\.)?)?(\(?\d{3}\)?|\d{3})( |-|\.)?(\d{3}( |-|\.)?\d{4})';

static const boldPattern = r'\*.*?\*';
static const italicPattern = r'\_.*?\_';
static const hashPattern = r'\B#+([^\x00-\x7F]|\w)+';
static const mentionPattern = r'\B@+([\w]+)\b';
}

0 comments on commit 61e3c2b

Please sign in to comment.