https://github.com/teragrep/glb_01
Teragrep GlobToRegex Library for Java
https://github.com/teragrep/glb_01
Last synced: 3 months ago
JSON representation
Teragrep GlobToRegex Library for Java
- Host: GitHub
- URL: https://github.com/teragrep/glb_01
- Owner: teragrep
- License: agpl-3.0
- Created: 2026-01-22T10:26:16.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2026-02-05T07:46:32.000Z (4 months ago)
- Last Synced: 2026-02-05T19:42:23.271Z (4 months ago)
- Language: Java
- Size: 72.3 KB
- Stars: 0
- Watchers: 0
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Teragrep GlobToRegex Library for Java
Teragrep GlobToRegex Library converts a https://en.wikipedia.org/wiki/Glob_(programming)[Glob pattern] into Java https://en.wikipedia.org/wiki/Regular_expression[regular expression].
== Features
Conversion supports following Glob expressions:
- Alternatives with nesting support (Braces)
- Character classes with negations (Brackets)
- Escapes (Backslashes)
- Wildcard characters (Questionmarks)
- Wildcard matches (Stars)
- Text into regex quotation
== Documentation
See the official documentation on https://docs.teragrep.com[docs.teragrep.com].
== Limitations
It is a pure Java implementation of following grammar and is bit hard to read.
[source,antlr4]
----
grammar Glob;
root // Glob.java
: rootSequence EOF
;
rootSequence // RootSequence.java
: (element | COMMA)*
;
element
: braceExp // BraceExpression.java
| charClass // CharacterClassExpression.java
| WILDCARD // WildcardExpression.java
| QUESTION // QuestionMarkExpression.java
| ESCAPED // EscapeExpression.java
| TEXT // Text.java
;
braceExp
: LBRACE element* (COMMA element*)* RBRACE
;
charClass
: LBRACK BANG? CLASS_CONTENT+ RBRACK
;
// --- Lexer Rules ---
ESCAPED : '\\' . ;
WILDCARD: '*' ;
QUESTION: '?' ;
LBRACK : '[' ;
RBRACK : ']' ;
LBRACE : '{' ;
RBRACE : '}' ;
COMMA : ',' ;
BANG : '!' ;
TEXT : ~[\\*?\[\]{},]+ ;
CLASS_CONTENT : ~[\]\\] | '\\' . ;
----
== How to [compile/use/implement]
=== Usage
[source,java]
----
import com.teragrep.glb_01.Glob;import com.teragrep.glb_01.GlobImpl;
Glob glob = new GlobImpl("test*Wildcard");
String regex = glob.asRegex();
System.out.println(regex); // Results into ^\Qtest\E.*\QWildcard\E$
----
== Contributing
// Change the repository name in the issues link to match with your project's name
You can involve yourself with our project by https://github.com/teragrep/glb_01/issues/new/choose[opening an issue] or submitting a pull request.
Contribution requirements:
. *All changes must be accompanied by a new or changed test.* If you think testing is not required in your pull request, include a sufficient explanation as why you think so.
. Security checks must pass
. Pull requests must align with the principles and http://www.extremeprogramming.org/values.html[values] of extreme programming.
. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).
Read more in our https://github.com/teragrep/teragrep/blob/main/contributing.adoc[Contributing Guideline].
=== Contributor License Agreement
Contributors must sign https://github.com/teragrep/teragrep/blob/main/cla.adoc[Teragrep Contributor License Agreement] before a pull request is accepted to organization's repositories.
You need to submit the CLA only once. After submitting the CLA you can contribute to all Teragrep's repositories.