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

Simple Tweak to make the HELP more understandable #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 87 additions & 21 deletions generex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,94 @@ Generex is based on the library http://www.brics.dk/~amoeller/automaton/.
```java


Generex generex = new Generex("[0-3]([a-c]|[e-g]{1,2})");

// generate the second String in lexicographical order that match the given Regex.
String secondString = generex.getMatchedString(2);
System.out.println(secondString);// it print '0b'

// Generate all String that matches the given Regex.
List<String> matchedStrs = generex.getAllMatchedStrings();

// Using Generex iterator
Iterator iterator = generex.iterator();
while (iterator.hasNext()) {
System.out.print(iterator.next() + " ");
}
// it print 0a 0b 0c 0e 0ee 0e 0e 0f 0fe 0f 0f 0g 0ge 0g 0g 1a 1b 1c 1e
// 1ee 1e 1e 1f 1fe 1f 1f 1g 1ge 1g 1g 2a 2b 2c 2e 2ee 2e 2e 2f 2fe 2f 2f 2g
// 2ge 2g 2g 3a 3b 3c 3e 3ee 3e 3e 3f 3fe 3f 3f 3g 3ge 3g 3g 1ee

// Generate random String
String randomStr = generex.random();
System.out.println(randomStr);// a random value from the previous String list
/**
* Copyright 2014 y.mifrah
*

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mifmif.common.regex;

import java.util.List;

/**
* @author y.mifrah
*
*/
public class Main {
public static void main(String[] args) {
String raw = "user@server[0-2][0-2]env.sub.domain.sufix";
String parse = parseRawInput(raw);
Generex generex = new Generex(parse);

// Generate all String that matches the given Regex.
List<String> matchedStrs = generex.getAllMatchedStrings();

for (String str : matchedStrs) {
System.out.println(str);
}

}

/**
* Parses the raw input.
*
* @param raw
* the raw
* @return the string
*/
private static String parseRawInput(String raw) {
System.out.println("RAW : " + raw);
StringBuilder build = new StringBuilder();
for (char c : raw.toCharArray()) {
switch (c) {
/*
* These are special cases that needs to be escaped. If these chars
* are allowed this would hang the regexp generator.
*/
case '@':
case '.':
build.append("\\").append(c);
break;
default:
build.append(c);

}
}
System.out.println("PARSED: " + build);
return build.toString();
}
}


```
**Output:**
```
RAW : user@server[0-2][0-2]env.sub.domain.sufix
PARSED: user\@server[0-2][0-2]env\.sub\.domain\.sufix
user@server00env.sub.domain.sufix
user@server01env.sub.domain.sufix
user@server02env.sub.domain.sufix
user@server10env.sub.domain.sufix
user@server11env.sub.domain.sufix
user@server12env.sub.domain.sufix
user@server20env.sub.domain.sufix
user@server21env.sub.domain.sufix
user@server22env.sub.domain.sufix



```

**License**
Expand Down
73 changes: 43 additions & 30 deletions generex/src/com/mifmif/common/regex/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,51 @@

import java.util.List;

import com.mifmif.common.regex.util.Iterator;

/**
* @author y.mifrah
*
*
*/
public class Main {
public static void main(String[] args) {
Generex generex = new Generex("[0-3]([a-c]|[e-g]{1,2})");

// generate the second String in lexicographical order that match the
// given Regex.
String secondString = generex.getMatchedString(2);
System.out.println(secondString);// it print '0b'

// Generate all String that matches the given Regex.
List<String> matchedStrs = generex.getAllMatchedStrings();

// Using Generex iterator
Iterator iterator = generex.iterator();
while (iterator.hasNext()) {
System.out.print(iterator.next() + " ");
}
// it print 0a 0b 0c 0e 0ee 0e 0e 0f 0fe 0f 0f 0g 0ge 0g 0g 1a 1b 1c 1e
// 1ee
// 1e 1e 1f 1fe 1f 1f 1g 1ge 1g 1g 2a 2b 2c 2e 2ee 2e 2e 2f 2fe 2f 2f 2g
// 2ge 2g 2g 3a 3b 3c 3e 3ee 3e 3e 3f 3fe 3f 3f 3g 3ge 3g 3g 1ee

// Generate random String
String randomStr = generex.random();
System.out.println(randomStr);// a random value from the previous String
// list

}
public static void main(String[] args) {
String raw = "user@server[0-2][0-2]env.sub.domain.sufix";
String parse = parseRawInput(raw);
Generex generex = new Generex(parse);

// Generate all String that matches the given Regex.
List<String> matchedStrs = generex.getAllMatchedStrings();

for (String str : matchedStrs) {
System.out.println(str);
}

}

/**
* Parses the raw input.
*
* @param raw
* the raw
* @return the string
*/
private static String parseRawInput(String raw) {
System.out.println("RAW : " + raw);
StringBuilder build = new StringBuilder();
for (char c : raw.toCharArray()) {
switch (c) {
/*
* These are special cases that needs to be escaped. If these chars
* are allowed this would hang the regexp generator.
*/
case '@':
case '.':
build.append("\\").append(c);
break;
default:
build.append(c);

}
}
System.out.println("PARSED: " + build);
return build.toString();
}
}