Class UserSearchUtils
Pattern
s from them
that can be used to create Matcher
objects. Some methods create patterns that
are meant to be used with Matcher.matches()
, while others create patterns
meant to be used with Matcher.find()
. Please see each method javadoc for clarification.
Note: methods in the class will escape regex characters, which means that normal regex queries will not work, but will be instead interpreted as literal string searches.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Pattern
createContainsPattern
(String input, boolean allowGlobbing, int options) Creates a regular expression Pattern that will match all strings that contain the given input string.static Pattern
createEndsWithPattern
(String input, boolean allowGlobbing, int options) Creates a regular expression Pattern that will match all strings that end with the given input string.static Pattern
Generate a compiled representation of a regular expression, ignoring regex special characters .static Pattern
createPattern
(String input, boolean allowGlobbing, int options) Creates a regular expression Pattern that will match all strings that match exactly the given input string.static String
createPatternString
(String input, boolean allowGlobbing) Creates a regular expression that can be used to create a Pattern that will match all strings that match the given input string.static Pattern
createSearchPattern
(String input, boolean caseSensitive) Note: this is the default model of how to let users search for things in Ghidra.static Pattern
createStartsWithPattern
(String input, boolean allowGlobbing, int options) Creates a regular expression Pattern that will match all strings that start with the given input string.
-
Field Details
-
STAR
Wildcard string for matching 0 or more characters.- See Also:
-
NON_GLOB_BACKSLASH_PATTERN
A pattern that will find all '\' chars that are not followed by '*', '?' or another '\'
-
-
Constructor Details
-
UserSearchUtils
public UserSearchUtils()
-
-
Method Details
-
createSearchPattern
Note: this is the default model of how to let users search for things in Ghidra. This is NOT a tool to allow regex searching, but instead allows users to perform searches while using familiar globbing characters such as '*' and '?'.This method can be used with
Matcher.matches()
orMatcher.find()
.Create a regular expression from the given input. Note: the regular expression created by this method is not a pure regular expression. More specifically, many regular expression characters passed to this method will be escaped (see
escapeAllRegexCharacters(String)
.Also, globbing characters will be changed from a regular expression meaning to a command-line style glob meaning.
Note: This method will escape regular expression characters, such as:
- ?
- .
- $
- ...and many others
- Parameters:
input
- string to create a regular expression fromcaseSensitive
- true if the regular expression is case sensitive- Returns:
- Pattern the compiled regular expression
- Throws:
PatternSyntaxException
- if the input could be compiled
-
createLiteralSearchPattern
Generate a compiled representation of a regular expression, ignoring regex special characters . The resulting pattern will match the literal text string.This method can be used with
Matcher.matches()
orMatcher.find()
.This method will not turn globbing characters into regex characters. If you need that, then see the other methods of this class.
- Parameters:
text
- search string- Returns:
- Pattern the compiled regular expression
- Throws:
PatternSyntaxException
- if the input could be compiled
-
createStartsWithPattern
Creates a regular expression Pattern that will match all strings that start with the given input string.This method should only be used with
Matcher.matches()
.The returned regular expression Pattern should be used with the "matches" method on a Matcher. (As opposed to "find").
- Parameters:
input
- the string that you want to your matched strings to start with.allowGlobbing
- if true, globing characters (* and ?) will converted to regex wildcard patterns; otherwise, they will be escaped and searched as literals.options
- anyPattern
options desired. For example, you can passPattern.CASE_INSENSITIVE
to get case insensitivity.- Returns:
- a regular expression Pattern that will match all strings that start with the given input string.
-
createEndsWithPattern
Creates a regular expression Pattern that will match all strings that end with the given input string.This method should only be used with
Matcher.matches()
.The returned regular expression Pattern should be used with the "matches" method on a Matcher. (As opposed to "find").
- Parameters:
input
- the string that you want to your matched strings to end with.allowGlobbing
- if true, globing characters (* and ?) will converted to regex wildcard patterns; otherwise, they will be escaped and searched as literals.options
- anyPattern
options desired. For example, you can passPattern.CASE_INSENSITIVE
to get case insensitivity.- Returns:
- a regular expression Pattern that will match all strings that end with the given input string.
-
createContainsPattern
Creates a regular expression Pattern that will match all strings that contain the given input string.This method should only be used with
Matcher.matches()
.- Parameters:
input
- the string that you want to your matched strings to contain.allowGlobbing
- if true, globing characters (* and ?) will converted to regex wildcard patterns; otherwise, they will be escaped and searched as literals.options
- anyPattern
options desired. For example, you can passPattern.CASE_INSENSITIVE
to get case insensitivity.- Returns:
- a regular expression Pattern that will match all strings that contain the given input string.
-
createPattern
Creates a regular expression Pattern that will match all strings that match exactly the given input string.This method can be used with
Matcher.matches()
orMatcher.find()
.- Parameters:
input
- the string that you want to your matched strings to exactly match.allowGlobbing
- if true, globing characters (* and ?) will converted to regex wildcard patterns; otherwise, they will be escaped and searched as literals.options
- anyPattern
options desired. For example, you can passPattern.CASE_INSENSITIVE
to get case insensitivity.- Returns:
- a regular expression Pattern that will match all strings that exactly match with the given input string.
-
createPatternString
Creates a regular expression that can be used to create a Pattern that will match all strings that match the given input string.This method can be used with
Matcher.matches()
orMatcher.find()
.- Parameters:
input
- the string that you want to your matched strings to exactly match.allowGlobbing
- if true, globing characters (* and ?) will converted to regex wildcard patterns; otherwise, they will be escaped and searched as literals.- Returns:
- a regular expression Pattern String that will match all strings that exactly match with the given input string.
-