Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to define what any character "." means #83

Closed
fakemail324 opened this issue Jun 10, 2023 · 2 comments · Fixed by #85
Closed

Add ability to define what any character "." means #83

fakemail324 opened this issue Jun 10, 2023 · 2 comments · Fixed by #85
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@fakemail324
Copy link

I'd like to use RgxGen to generate file names from patterns provided by users. Some of them are like: ^file.*.txt$
I would be very helpful to be able to limit "any character" to some regex like [a-zA-Z0-9-_] to avoid illegal or not desired characters in the file name. It could be similar to solution used in: https://github.com/Cornutum/regexp-gen/blob/master/README.md#what-matches-dot

@fakemail324 fakemail324 added the enhancement New feature or request label Jun 10, 2023
@curious-odd-man curious-odd-man added this to the Version 1.5 milestone Jun 10, 2023
@curious-odd-man curious-odd-man linked a pull request Jun 11, 2023 that will close this issue
curious-odd-man added a commit that referenced this issue Jun 11, 2023
# Conflicts:
#	README.md
#	src/main/java/com/github/curiousoddman/rgxgen/config/RgxGenOption.java
#	src/main/java/com/github/curiousoddman/rgxgen/nodes/SymbolSet.java
#	src/main/java/com/github/curiousoddman/rgxgen/parsing/dflt/DefaultTreeBuilder.java
#	src/test/java/com/github/curiousoddman/rgxgen/util/SymbolSetTestUtils.java
curious-odd-man added a commit that referenced this issue Jun 11, 2023
…nyCharacterMeans

#83.property to define what any character means
@curious-odd-man
Copy link
Owner

Hello! This is now implemented, though only in a snapshot version.

Please feel free to try it out and provide any feedback

    <repositories>
        <repository>
            <id>snapshots-repository</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </repository>
    </repositories>
    
    <dependency>
        <groupId>com.github.curious-odd-man</groupId>
        <artifactId>rgxgen</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>

Here is a code example (note that API is slightly changed

public class Main {
    public static void main(String[] args) {
        RgxGenProperties properties = new RgxGenProperties();
        RgxGenOption.DOT_MATCHES_ONLY.setInProperties(properties, RgxGenCharsDefinition.of("abc"));
        RgxGen rgxGen = RgxGen.parse(properties, ".");
        String generatedValue = rgxGen.generate();      // Will produce either "a" or "b" or "c".
    }
}

@fakemail324
Copy link
Author

Thank you for the reply. That would also work. You could also consider extending this feature and instead of providing the list of characters that would match the "." you could define the regex that would replace the ".". The workaround I'm using right now is:

public class Main {
    private static final String DOT_PATTERN = "(?<!\\\\)\\.";
    private static final String DOT_REPLACEMENT_PATTERN = "[0-9a-zA-Z]";
    public static void main(String[] args) {
        RgxGen rgxGen = RgxGen.parse(".".replaceAll(DOT_PATTERN, DOT_REPLACEMENT_PATTERN));
        System.out.println(rgxGen.generate());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants