In Java, by default, the regular expression (regex) matching is case sensitive. To enable the regex case insensitive matching, add (?) prefix or enable the case insensitive flag directly in the Pattern.compile().

A regex pattern example.

Pattern = Registrar:\\s(.*)

Case Insensitive, add (?) prefix.

Pattern = (?)Registrar:\\s(.*)

Case Insensitive, add Pattern.CASE_INSENSITIVE flag.

Pattern.compile("Registrar:\\s(.*)", Pattern.CASE_INSENSITIVE);

1. RegEx Example

Example to use regex case insensitive matching to get the “Registrar” information.

package com.mkyong.regex

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RunExampleTest{
	private Pattern registrarPattern = Pattern.compile(REGISTRAR_PATTERN);
	/*private Pattern registrarPattern = 
	private Matcher matcher;

	private static final String REGISTRAR_PATTERN = "(?)Registrar:\\s(.*)";
	public static void main(String[] args) {
		String data = "Testing... \n" +
			"Registrar:\n" +
			"registrar:\n" +
			"end testing";
		RunExampleTest obj = new RunExampleTest();
		List<String> list = obj.getRegistrar(data);
	private List<String> getRegistrar(String data){
		List<String> result = new ArrayList<String>();
		matcher = registrarPattern.matcher(data);

		while (matcher.find()) {
		return result;


If the (?) is deleted, only the [] will be returned. (Case sensitive).


  1. Wikipedia : Case Sensitivity
  2. Wikipedia : Regular Expression/