パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.0.0

recursive_regex

区切り文字で囲まれたテキストブロックを分離し、各ブロックに個別にパターンを適用する RegExp の実装です。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.3万
いいね数
10
Pub ポイント
130

パッケージをインストール

flutter pub add recursive_regex

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

ネストされた括弧やカスタム区切り文字などの区切りテキストブロックを再帰的に解析および処理するための、RegExp 機能を拡張する Flutter/Dart パッケージです。各独立したブロックにパターンを個別に適用することで、複雑な文字列内の構造化テキストを正確に抽出・変換できます。テンプレート、式、マークアップ言語などのネスト構文の解析に最適です。モバイル、Web、デスクトップなど複数のプラットフォームをサポートしており、高度なテキスト操作を必要とするクロスプラットフォームアプリケーションに適しています。

用途

  • ネストされたテンプレートの解析
  • 区切りブロックからコンテンツを抽出する
  • 再帰を使用した構造化テキストの処理
  • カスタムDSLの実装
  • コード内のネストされた式の処理
  • マルチレイヤード文字列におけるテキスト変換

主な機能

  • 再帰的ブロックの分離
  • ブロックごとの独立したパターン適用
  • カスタム区切り文字のサポート
  • クロスプラットフォーム互換性
  • シンプルな API インテグレーション
  • 効率的なテキスト処理

適している対象

  • テンプレートエンジンを開発する開発者
  • ネストされたテキスト解析を必要とするツール
  • 構造化文字列データを持つアプリケーション
  • DSL または言語パーサーの実装
  • テキストエディタまたはコードアナライザー

注意事項

  • 深くネストされた構造を効率的に処理できない可能性があります
  • 慎重な区切り記号の設計が必要です
  • パフォーマンスは入力の複雑さに依存します
  • テキストベースのパターンに限定
  • 再帰的でない解析のニーズには適していません
  • 極端なネストによるスタックオーバーフローの可能性

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

recursive_regex

pub package

An implementation of Dart's RegExp class that isolates delimited blocks of text and applies the delimited pattern to each block separately.

The [RecursiveRegex] class implements Dart's [RegExp] class. As such, it has all of the same methods as [RegExp] and can be used interchangeably with [RegExp]s.

Usage

import 'package:recursive_regex/recursive_regex.dart';

[RecursiveRegex] has 2 required parameters, [startDelimiter] and [endDelimiter]. Both accept a [RegExp], must not be null, and must not have identical patterns.

final regex = RecursiveRegex(
  startDelimiter: RegExp(r'<'),
  endDelimiter: RegExp(r'>'),
);

This [RecursiveRegex], if applied to a string, would capture every block of text delimited by the < and > characters.

final input = 'a<b<c<d><e>f>g>h';
regex.allMatches(input); // ['<b<c<d><e>f>g>']

By default, only top-level blocks of delimited text are matched. To match every block of delimited text, nested or not, [global] can be flagged true.

final input = '<a<b<c><d>>>';

final regex = RecursiveRegex(
  startDelimiter: RegExp(r'<'),
  endDelimiter: RegExp(r'>'),
  global: true,
);

regex.allMatches(input); // ['<c>', '<d>', '<b<c><d>>', '<a<b<c><d>>>']

Delimited blocks of text are matched in the order that they're closed.

Note: [RecursiveRegex] is not optimized for parsing strings that do not contain nested blocks of delimited text, [RegExp] would be more efficient if you know the string doesn't contain any nested delimiters.

[prepended] & [appended] Patterns

[Pattern]s can be provided to [RecursiveRegex]'s [prepended] and [appended] parameters to disqualify any matched set of delimiters that aren't lead and/or followed by the provided [Pattern].

final input = '0<a<b<1<c>2>3<d>>>';

final prepended = RecursiveRegex(
  startDelimiter: RegExp(r'<'),
  endDelimiter: RegExp(r'>'),
  prepended: RegExp(r'[0-9]'),
  global: true,
);

prepended.allMatches(input); // ['1<c>', '3<d>', '0<a<b<1<c>2>3<d>>>']

final appended = RecursiveRegex(
  startDelimiter: RegExp(r'<'),
  endDelimiter: RegExp(r'>'),
  appended: RegExp(r'[0-9]'),
  global: true,
);

appended.allMatches(input); // ['<c>2', '<1<c>2>3']

final both = RecursiveRegex(
  startDelimiter: RegExp(r'<'),
  endDelimiter: RegExp(r'>'),
  prepended: RegExp(r'[0-9]'),
  appended: RegExp(r'[0-9]'),
  global: true,
);

both.allMatches(input); // ['0<a<b<1<c>2>3']
inverseMatch

A [Pattern] can be provided to the [inverseMatch] parameter to define a pattern that should be matched, but only if it's not delimited.

Note: [global] has no affect on the matches if an [inverseMatch] pattern is provided, as all lower-level matches are delimited.

final input = 'a<b<c<d><e>f>g>h';

final regex = RecursiveRegex(
  startDelimiter: RegExp(r'<'),
  endDelimiter: RegExp(r'>'),
  inverseMatch: RegExp(r'[a-z]'),
  global: true,
);

regex.allMatches(input); // ['a', 'h']

Capture Groups

The block of text captured between the delimiters can be captured in a named group by providing [RecursiveRegex] with a [captureGroupName].

final input = '<!ELEMENT [ some markup ]>';

final regex = RecursiveRegex(
  startDelimiter: RegExp(r'<!(?<type>\w*)\s*\['),
  endDelimiter: RegExp(r']>'),
  captureGroupName: 'value',
);

print(regex.firstMatch(input).namedGroup('value')); // ' some markup '

// Groups named within the delimiters can also be called.
print(regex.firstMatch(input).namedGroup('type')); // 'ELEMENT'

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。