Programming Articles - Page 2157 of 3366

Matching Nonprintable Characters using Java regex

Maruthi Krishna
Updated on 13-Jan-2020 06:06:18

1K+ Views

There are 7 common non printable characters used in general and each character has its own hexadecimal representation.NamecharactersHexa-decimal representationbell\a0x07Escape\e0x1BForm feed\f0x0CLine feed0x0ACarriage return\r0X0DHorizontal tab\t0X09Vertical tab\v0X0BExample 1 Live DemoFollowing Java program accepts an input text and counts the number of tab spaces in it −import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample1 {    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input text: ");       String input = sc.nextLine();       String regex = "\t";       //Creating a pattern object       Pattern pattern = ... Read More

Regular expression “[X?+] ” Metacharacter Java

Maruthi Krishna
Updated on 13-Jan-2020 06:02:27

202 Views

The Possessive Quantifier [X?+] matches the X present once or not present at all.Example Live Demopackage com.tutorialspoint; import java.util.regex.Matcher; import java.util.regex.Pattern; public class PossesiveQuantifierDemo {    private static final String REGEX = "T?+";    private static final String INPUT = "abcdTatW";    public static void main(String[] args) {       // create a pattern       Pattern pattern = Pattern.compile(REGEX);       // get a matcher object       Matcher matcher = pattern.matcher(INPUT);       while(matcher.find()) {          //Prints the start index of the match.          System.out.println("Match String start(): "+matcher.start()); ... Read More

Counting the number of groups Java regular expression

Maruthi Krishna
Updated on 13-Jan-2020 05:59:52

1K+ Views

You can treat multiple characters as a single unit by capturing them as groups. You just need to place these characters inside a set of parentheses.You can count the number of groups in the current match using the groupCount() method of the Matcher class. This method calculates the number of capturing groups in the current match and returns it.Example Live Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Test {    public static void main(String[] args) {       String str1 = "This is an example HTML script where ever alternative word is bold.";       //Regular expression to match contents ... Read More

Explain character classes in Java regular expressions

Deepti S
Updated on 29-Aug-2023 15:47:34

438 Views

Java regular expressions, is often known as rege. It is employed for searching and manipulating text. They are utilized in numerous applications. Online scraping, email screening, and password validation are a few of them.A pattern that can be employed to match a specific character sequence in a string is also known as a regular expression. To build the pattern, a special syntax involving quantifiers, character classes, wildcard characters, and ordinary characters is employed. Character classes are characters that can be matched by a regular expression. They are defined using square brackets []. For instance, the character class [abc] matches the ... Read More

Difference between float and double in C/C++

Mahesh Parahar
Updated on 24-Feb-2020 08:04:39

2K+ Views

As we know that in C/C++ we require float and double data type for the representation of Floating point numbers i.e the numbers which have decimal part with them.Now on the basis of precision provided by both of these data types we can differentiate between both of them.In simple words it could be state that double has 2x more precision as compare than float which means that double data type has double precision than as compare to that of float data type.In terms of number of precision it can be stated as double has 64 bit precision for floating point ... Read More

Reluctant quantifiers Java Regular expressions

Maruthi Krishna
Updated on 13-Jan-2020 05:53:17

969 Views

Greedy quantifiers are the default quantifiers. A greedy quantifier matches as much as possible from the input string (longest match possible) if match not occurred it leaves the last character and matches again.Whereas a reluctant or, non-greedy quantifier matches as little as possible, initially the non-greedy quantifier matches the first character if match not occurred it adds another character from the input string and tries to match.If you place a "?" after a greedy quantifier it becomes reluctant or non-greedy quantifier. Following is the list of reluctant quantifiers −QuantifierDescriptionre*?Matches zero or more occurrences.re??Matches zero or, 1 occurrence.re+?Matches one or more ... Read More

Java regex program to match parenthesis "(" or, ")".

Maruthi Krishna
Updated on 21-Feb-2020 11:27:01

6K+ Views

Following regular expression accepts a string with parenthesis −"^.*[\(\)].*$";^ matches the starting of the sentence..* Matches zero or more (any) characters.[\(\)] matching parenthesis.$ indicates the end of the sentence.Example 1 Live Demoimport java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class SampleTest {    public static void main( String args[] ) {       String regex = "^.*[\(\)].*$";       //Reading input from user       Scanner sc = new Scanner(System.in);       System.out.println("Enter data: ");       String input = sc.nextLine();       //Instantiating the Pattern class       Pattern pattern = Pattern.compile(regex);     ... Read More

Difference between Structure and Array in C

Mahesh Parahar
Updated on 25-Feb-2020 07:13:01

7K+ Views

In C both Structure and Array are used as container for data types i.e in both structure and array we can store data and also can perform different operations over them.On the basis of internal implementation following are some basic differences between both.Sr. No.KeyStructureArray1DefinitionStructure can be defined as a data structure used as container which can hold variables of different types.On other hand Array is a type of data structure used as container which can hold variables of same type and do not support multiple data type variables.2Memory AllocationMemory allocation for input data in structure does not necessary to be ... Read More

Difference between strlen() and sizeof() for string in C Program

Mahesh Parahar
Updated on 25-Feb-2020 06:57:24

332 Views

As we know that in programming string can be defined as the collection of characters. Now for the requirement of finding how many characters are being used to create a string, C provides two approaches which are strlen() and sizeof().As mentioned in above point both of these methods are used to find out the length of target operand but on the basis of their internal implementation following are some basic differences between both.Sr. No.Keystrlen()sizeof()1Definitionstrlen() is a predefined function defined in a Header file named string.h in C.On other hand sizeof() is a Unary operator and not a predefined function.2Implementationstrlen is ... Read More

Explain quantifiers in Java regular expressions

Alshifa Hasnain
Updated on 12-Jun-2025 17:31:35

675 Views

Quantifiers in Java are special characters that allow you to specify the number of times a character or group of characters can occur in a regular expression. The most common quantifiers are: *: One or more instances of the character or set of characters that came before it. ?: The character or set of characters before it, either zero or one instance. ... Read More

Advertisements