Skip to content

Commit

Permalink
added regex scanner options: multiline, dotall
Browse files Browse the repository at this point in the history
  • Loading branch information
JuicyDragon committed Jan 22, 2021
1 parent d973ee2 commit d1194b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public PatternInfo(String title, String expression){
* Compiles the regular expression String provided into a Java Pattern object
* @param caseSensitive Whether it should be case sensitive
*/
public void compile(boolean caseSensitive){
public void compile(boolean caseSensitive, boolean multiline, boolean dotAll){
if(pattern == null){
if(caseSensitive)
pattern = Pattern.compile(expression);
else
pattern = Pattern.compile(expression,Pattern.CASE_INSENSITIVE);
int bitflags = 0;
if(!caseSensitive) { bitflags |= Pattern.CASE_INSENSITIVE; }
if(multiline) { bitflags |= Pattern.MULTILINE; }
if(dotAll) { bitflags |= Pattern.DOTALL; }
pattern = Pattern.compile(expression,bitflags);
}
}

Expand Down
28 changes: 23 additions & 5 deletions Java/src/main/java/com/nuix/superutilities/regex/RegexScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static void setMaxToStringLength(int maxLength){

private boolean scanContent = true;
private boolean caseSensitive = false;
private boolean multiline = false;
private boolean dotall = false;
private boolean captureContextualText = true;
private int contextSize = 100;

Expand Down Expand Up @@ -134,7 +136,7 @@ public List<ItemRegexMatchCollection> scanItems(Collection<Item> items){
List<ItemRegexMatchCollection> result = new ArrayList<ItemRegexMatchCollection>();

for (PatternInfo p : patterns) {
p.compile(caseSensitive);
p.compile(caseSensitive,multiline,dotall);
}

for (Item item : items) {
Expand Down Expand Up @@ -163,7 +165,7 @@ public void scanItems(Collection<Item> items, Consumer<ItemRegexMatchCollection>
abortWasRequested = false;

for (PatternInfo p : patterns) {
p.compile(caseSensitive);
p.compile(caseSensitive,multiline,dotall);
}

int itemIndex = 0;
Expand Down Expand Up @@ -196,7 +198,7 @@ public void scanItemsParallel(Collection<Item> items, Consumer<ItemRegexMatchCol
abortWasRequested = false;

for (PatternInfo p : patterns) {
p.compile(caseSensitive);
p.compile(caseSensitive,multiline,dotall);
}

AtomicInteger itemIndex = new AtomicInteger(0);
Expand Down Expand Up @@ -242,7 +244,7 @@ public void scanItemsParallel(Collection<Item> items, Consumer<ItemRegexMatchCol
abortWasRequested = false;

for (PatternInfo p : patterns) {
p.compile(caseSensitive);
p.compile(caseSensitive,multiline,dotall);
}

AtomicInteger itemIndex = new AtomicInteger(0);
Expand Down Expand Up @@ -306,7 +308,7 @@ protected ItemRegexMatchCollection scanItem(Item item) {
Set<String> entityValues = item.getEntities(namedEntityType);
for(String entityValue : entityValues) {
PatternInfo entityPattern = new PatternInfo(namedEntityType, "\\Q"+entityValue+"\\E");
entityPattern.compile(caseSensitive);
entityPattern.compile(caseSensitive,multiline,dotall);
patternsToScanFor.add(entityPattern);
}
} catch (IOException e) {
Expand Down Expand Up @@ -537,6 +539,22 @@ public void setCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}

public boolean getMultiline() {
return multiline;
}

public void setMultiline(boolean multiline) {
this.multiline = multiline;
}

public boolean getDotall() {
return dotall;
}

public void setDotall(boolean dotall) {
this.dotall = dotall;
}

public boolean getCaptureContextualText() {
return captureContextualText;
}
Expand Down

0 comments on commit d1194b7

Please sign in to comment.