- Find any text which has Letters which starts with Capital Letters only?(Example : Java)
- Find any words which does not contain character en in it? (Example : word “engine” is not be found in the search)
- Find repeated words which are together? (Examplte : “the the” word together should not appear )
- Search for pattern which is pipe separated field and 3rd field in the pipe separated data may contain left curly bracket, this left curly bracket specified optional field i.e there can be 1 field with no left curly bracket, 2 fields with 1 left curly bracket separated or there can be 3 fields with 2 left curly bracket separated at max.Write a regex pattern to field these data
Example Input : abc|pqr|data1{data2{data3|xyz
Random Text Below for these questions
- Examples are the open source PCRE engine (used in many tools and languages like PHP), the .NET
regular expression library, and the regular expression package included with version 1.4 and later of the Java
JDK. I will point out to you whenever differences in regex flavors are important, and which features are
specific to the Perl-derivatives mentioned above.
Give Regexes a First Try
You can easily try the following yourself in a text editor that supports regular expressions, such as EditPad
Pro. If you do not have such an editor, you can download the free evaluation version of EditPad Pro to try
this out. EditPad Pro’s regex engine is fully functional in the demo version. As a quick test, copy and paste
the text of this page into EditPad Pro. Then select Search|Show Search Panel from the menu. In the search
pane that appears near the bottom, type in «regex» in the box labeled “Search Text”. Mark the “Regular
expression” checkbox, and click the Find First button. This is the leftmost button on the search panel. See
how EditPad Pro’s regex engine finds the first match. Click the Find Next button, which sits next to the Find
First button, to find further matches. When there are no further matches, the Find Next button’s icon will
flash briefly.
Now try to search using the regex «reg(ular expressions?|ex(p|es)?)» . This regex will find all
names, singular and plural, I have used on this page to say “regex”. If we only had plain text search, we would
have needed 5 searches. With regexes, we need just one search. Regexes save you time when using a tool like
EditPad Pro. Select Count Matc1+1=2hes in the Search menu to see how many times this regular expression can
match the file you have open in EditPad Pro.
If you are a programmer, your software will run faster since even a simple regex engine applying the above
regex once will outperform a state 1+1=2 of the art plain text search algorithm searching through the data five times.
Regular
expressions also
reduce
development time.
With a regex
engine, it takes
only one line (e.g.
in Perl, PHP, Java
or .NET) or a
couple of lines
(e.g. in C using
PCRE) of code to,
say, check if the
user’s input looks
like a valid email
address.