Regular Expression: A Construct in Java

Maruthi Krishna
Updated on 19-Nov-2019 06:18:18

242 Views

The subexpression/metacharacter “\A” matches the beginning of the entire string.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "\AHi";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }OutputNumber of matches: 1Example 2Following Java program accepts a ... Read More

Regular Expression Construct in Java

Maruthi Krishna
Updated on 19-Nov-2019 06:17:16

227 Views

The subexpression/metacharacter “[^...]” matches any single character, not in brackets.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpecifiedCharacters {    public static void main( String args[] ) {       String regex = "[^hwtyoupi]";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }OutputNumber of matches: 21Example 2The following Java program accepts ... Read More

Sub-Expression in Java Regular Expressions

Maruthi Krishna
Updated on 19-Nov-2019 06:04:54

349 Views

The subexpression “[...]” matches any single character specified in the brackets.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpecifiedCharacters {    public static void main( String args[] ) {       String regex = "[hwt]";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }OutputNumber of matches: 6Example 2The following Java program ... Read More

Regular Expression Metacharacter in Java

Maruthi Krishna
Updated on 18-Nov-2019 11:59:46

172 Views

The subexpression/metacharacter “re*” matches 0 or more occurrences of the preceding expression.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "aabc*";       String input = "aabcabcaabcabbcaabcbcaabc";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }OutputNumber of matches: 4Example 2import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchAllCharacters ... Read More

Explain Regular Expression Metacharacter in Java

Maruthi Krishna
Updated on 18-Nov-2019 11:57:12

283 Views

The subexpression/metacharacter “\A” matches the beginning of the entire string.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "\AHi";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }OutputNumber of matches: 1Example2Following Java program accepts a string ... Read More

Regular Expression Dot Metacharacter in Java

Maruthi Krishna
Updated on 18-Nov-2019 10:29:25

1K+ Views

The subexpression/metacharacter “.” matches any single character except a newline.Example1import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchesAll {    public static void main( String args[] ) {       String regex = ".";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }OutputNumber of matches: 40Example 2The following Java program accepts 5 ... Read More

Regular Expression Dollar Metacharacter in Java

Maruthi Krishna
Updated on 18-Nov-2019 10:17:40

1K+ Views

The subexpression/metacharacter “$” matches the end of a line.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class EndWith {    public static void main( String args[] ) {       String regex = "Tutorialspoint$";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;          System.out.println("Number of matches: "+count);       }    } }OutputNumber of matches: 1Example 2The following Java program accepts ... Read More

Regular Expression Caret Metacharacter in Java

Maruthi Krishna
Updated on 18-Nov-2019 10:12:52

671 Views

The subexpression/metacharacter “^” matches the beginning of a line. If you use this in a regular expression, it matches the sentence succeeding it in the input string.Example 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "^Hi how are you";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;     ... Read More

Difference Between Application Context and BeanFactory in Spring Framework

Mahesh Parahar
Updated on 18-Nov-2019 07:28:36

4K+ Views

Spring framework provides two IOC container for managing, configuring and manipulating beans. One is BeanFactory and the other is Application Context. The application context interface extends BeanFactory to enhance the functionality of BeanFactory. In new Spring versions, BeanFactory is replaced with ApplicationContext. But still, BeanFactory exists for backward compatibility. Spring version 2.0 and above, is used BeanPostProcessor extension point(Interface which provides some callback methods that we can implement to customize the instantiation logic, dependency-resolution logic and etc ). So, if you are using BeanFactory then some of the functionality such as AOP and transaction will not work without doing some extra configuration.Sr. No.KeyBeanfactoryApplication ... Read More

Difference Between Lazy and Eager Loading in Hibernate

Mahesh Parahar
Updated on 18-Nov-2019 06:20:10

16K+ Views

Lazy and Eager are two types of data loading strategies in ORMs such as hibernate and eclipse Link.  These data loading strategies we used when one entity class is having references to other Entities like Employee and Phone (phone in the employee). Lazy Loading − Associated data loads only when we explicitly call getter or size method.Use Lazy Loading when you are using one-to-many collections.Use Lazy Loading when you are sure that you are not using related entities. Egare Loading − Data loading happens at the time of their parent is fetched. Use Eager Loading when the relations are not too much. Thus, ... Read More

Advertisements