중첩된 괄호나 사용자 정의 구분 기호와 같은 구분된 텍스트 블록을 재귀적으로 분석하고 처리할 수 있도록 RegExp 기능을 확장하는 Flutter/Dart 패키지입니다. 각 고립된 블록에 독립적으로 패턴을 적용하여 복잡한 문자열 내에서 구조화된 텍스트를 정확하게 추출하고 변환할 수 있습니다. 템플릿, 표현식 또는 마크업 언어와 같은 중첩 구문을 분석하는 데 이상적입니다. 모바일, 웹, 데스크톱 등 다양한 플랫폼을 지원하여 고급 텍스트 조작이 필요한 크로스플랫폼 애플리케이션에 유용합니다.
사용 사례
중첩된 템플릿 파싱
구분 블록에서 콘텐츠 추출
재귀를 사용하여 구조화된 텍스트 처리
사용자 정의 DSL 구현
코드 내 중첩된 표현식 처리
다중 계층 문자열 내 텍스트 변환
주요 기능
재귀 블록 격리
블록별로 독립적인 패턴 적용
사용자 정의 구분 기호 지원
크로스 플랫폼 호환성
간단한 API 통합
효율적인 텍스트 처리
적합한 대상
템플릿 엔진을 구축하는 개발자
중첩 텍스트 분석이 필요한 도구
구조화된 문자열 데이터를 가진 애플리케이션
DSL 또는 언어 파서 구현
텍스트 편집기 또는 코드 분석기
고려 사항
깊이 중첩된 구조를 효율적으로 처리하지 못할 수 있습니다
정교한 구분 기호 설계가 필요합니다
성능은 입력 복잡도에 따라 달라집니다
텍스트 기반 패턴으로 제한
비재귀적 구문 분석 요구 사항에 적합하지 않습니다
극도의 중첩으로 인한 스택 오버플로 가능성
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
recursive_regex
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.
[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.
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].
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'