-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Helper to find a value in a string using a Regex.static String
Find a value by regular expression, for testingstatic boolean
Returns whether the regular expression matched the data Note: This is a poor-performance method, mainly used as a quick helper where performance concerns don't exist,since each call to this method will compile the regular expression.
-
Method Details
-
find
Helper to find a value in a string using a Regex. Note, this is not nearly as performant, since each call to this method will compile the regular expression.- Returns:
- returns the first match found, or an empty string
-
isFound
Returns whether the regular expression matched the data Note: This is a poor-performance method, mainly used as a quick helper where performance concerns don't exist,since each call to this method will compile the regular expression. -
find
Find a value by regular expression, for testingA helper method to make things it easier to find a value in a string using a Regex. This method is slow, since each call will compile the regular expression.
This version is similar to
find(String, String)
except that it allows you to specify a match group by name. For example, here's a regex with a named match group, in this example the name is "namevalue":"\\bname\\b=\"(?<namevalue>.*?)\""
Thus, to use it here, you would search like this:
find("\\bname\\b=\"(?<namevalue>.*?)\"", data, "namevalue")
To summarize: in a regex, you specify a matching group by surrounding it with parentheses. To name it, you insert right after the opening parenthesis a question mark and then a string literal surrounded by angle brackets
Important: the name of the match group must be alphanumeric - do not use any special characters or punctuation
- Returns:
- returns the first match found, or an empty string
-