패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.0.0

recursive_regex

구분된 텍스트 블록을 분리하고 각 블록에 별도로 패턴을 적용하는 RegExp의 구현입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.3만
좋아요
10
Pub 점수
130

패키지 설치

flutter pub add recursive_regex

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

중첩된 괄호나 사용자 정의 구분 기호와 같은 구분된 텍스트 블록을 재귀적으로 분석하고 처리할 수 있도록 RegExp 기능을 확장하는 Flutter/Dart 패키지입니다. 각 고립된 블록에 독립적으로 패턴을 적용하여 복잡한 문자열 내에서 구조화된 텍스트를 정확하게 추출하고 변환할 수 있습니다. 템플릿, 표현식 또는 마크업 언어와 같은 중첩 구문을 분석하는 데 이상적입니다. 모바일, 웹, 데스크톱 등 다양한 플랫폼을 지원하여 고급 텍스트 조작이 필요한 크로스플랫폼 애플리케이션에 유용합니다.

사용 사례

  • 중첩된 템플릿 파싱
  • 구분 블록에서 콘텐츠 추출
  • 재귀를 사용하여 구조화된 텍스트 처리
  • 사용자 정의 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.