Blog Archives

8 Regular Expressions (aka Regex) by examples for Java developers

Q1 How will you go about implementing the following validation rules for a user name?

— user name must be between 2 and 17 characters long.
— valid characters are A to Z, a to z, 0 to 9, . (full-stop), _ (underscore) and – (hyphen)
— user name must begin with an alphabetic character.
— user name must not end with a . (full stop) or _ (underscore) or – (hyphen).

A1 The above rules can be implemented with a regular expression as shown below:



Power of regex for productivity with Notepad++ or Sublime Text

This post is based on industrial strength examples of applying regular expression to increase your productivity as a software engineer. Many text editors like Notepad++, Sublime Text, Atom, etc support regular expressions in their find and replace functionality. If you are new to regular expression, practice at https://regexr.com/ or https://regex101.com/

Note: Don’t copy paste theses regexes, but type them in your text editor’s find/replace dialogue box.

#1: Adding quotes to CSV file entries

Problem Statement: If you have a CSV file where you want to add quotes (i.e. “) around its each entry. For example:

Convert csv entries in .csv …

Tags:

Regular Expressions interview Q&As for Java developers

Q1 What’s the difference between a wildcard and a regular expression? A1 A wildcard is a generic term referring to something that can be substituted for all possibilities. In computer terms, usually a simple “wildcard” is just a * that can match one or more characters, and possibly a ?…



Regular Expressions Practice – Java Matcher class csv example

Let’s look at how to validate a CSV (i.e. Comma Separated Value) string using regular expression in Java using the Pattern & Matcher classes. Refer to the Java Pattern class API for what each syntax mean. Regular expressions may look complex, but if you understand the patterns and break them down into simpler steps, they will become easier to comprehend.

Comma separated digits

The below is a simple example of how to validate comma separated digits. The “^” at the beginning and “$” at end means match the full string. Sample input = “1, 2, 3 …



Regular Expressions Practice – Java Matcher class tokenize example

If you are new to regular expressions then start with 8 Regular Expressions (aka Regex) by examples for Java developers.

This is a real life scenario as to how regular expressions can come in handy to solve day to day problems. Regular expressions are very powerful and can be used by developers & data engineers to solve problems & save time. Let’s start with the Matcher class basics & then into a tokenising example.

Q1. What is the difference between matches() and find() in Java Regex?
A1. The matches() tries to match the expression against the entire string and …



300+ Java & Big Data FAQs - Quick Prep

Java & Big Data Tutorials

Top