Regular Expressions: What are They and Why do They Matter?
When looking at the String.Split
function for the programming assignment, I noticed that one of its parameters
was “String regex. The description for this method read “Splits this string
around matches of the given regular expression”. What I gathered that to mean
was that this method could split a string based on a pattern that you gave to
the method. But what exactly is a pattern and what is a regular expression?
Regular expressions (called regex
sometimes) are actually a huge part of java and other programming languages. Regular
expression is an API in java which allows us to define a pattern which can be
used to do all sorts of things with text. You can use it to search for a specific
pattern, modify text using it, and like I mentioned earlier, you can split a
string using one. These patterns can range from just a single character, to
complex strings with characters, numbers, and symbols. Its really up to what
the programmer wants to use them for. One use for regular expressions it
matching. Using these patterns, you can search for instances of the patterns in
text and do something as simple as return a Boolean if the pattern is found, or
replace every instance of the pattern with something else completely. There are
an incredible amount of possible actions you can perform on text using a
regular expression. In the tables below there are some already existing
patterns but a programmer can design their own pattern if they wish. The Regex
is a powerful tool in java and can be incredibly useful to us whenever we deal
with text in a program.
Sources:
The quote is from: http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
all the tables are from :http://www.vogella.com/tutorials/JavaRegular Expressions /article .html#what-are-regular-expressions
other sources used:
http://www.ocpsoft.org/opensource/guide-to-regular-expressions-in-java-part-1/#section-14
http://www.javatpoint.com/java-regex

No comments:
Post a Comment