Programming Articles - Page 3275 of 3366

How regular expression back references works in Python?

Nikitasha Shrivastava
Updated on 24-Apr-2025 18:07:20

885 Views

Backreferences in regular expressions allow us to reuse a previously recorded group inside the same regex pattern. This ability is very useful when we want to match recurrent patterns in strings. What are Backreferences? A regular expression reference to a previously recorded group is called a backreference. When parentheses "()" are used in a regex pattern, a group is formed. Each group is assigned a number; the number for the first group is 1. We can refer to these recorded groups in our regex by using the backslash \ after the group number. Basic Syntax Here is the basic ... Read More

What is the groups() method in regular expressions in Python?

Nikitasha Shrivastava
Updated on 24-Apr-2025 12:33:32

11K+ Views

In Python, we can use regular expressions when looking for patterns in text. So we have a useful method called groups() in Python. This method helps us to find and manage many parts of a pattern. So in this article will explain how the groups() method works. The groups() Method The match.group() function in Python's re module is used to get the captured groups after a successful regular expression match. When a regular expression uses parentheses, it creates capturing groups with the matched substrings. The match.group() method returns the captured substrings. The following is the syntax of the groups() method ... Read More

What are regular expression repetition cases in Python?

Md Waqar Tabish
Updated on 24-Apr-2025 11:39:43

2K+ Views

We can build regular expressions that recognize repeated character groups using a few special characters. The following metacharacters can be used to search for a character or set of repeated characters. The question mark was the first repeating operator or quantifier developed. It effectively makes it optional by instructing the engine to try matching the previous token 0 or 1 times. Matching Simple HTML Tags Using Regular Expressions The engine is instructed to try matching the previous token zero or more times by the asterisk or star. The plus instructs the engine to make one or more attempts to match ... Read More

How not to match a character after repetition in Python Regex?

Nikitasha Shrivastava
Updated on 26-May-2025 18:44:05

415 Views

Regular expression, or regex, is a useful tool in Python that helps identifying and processing of text patterns. It helps you cut, edit and check text in different ways. In this article, we will talk about how not to match a character after repetition in regex and look at five different examples. We will provide you a clear explanation to help you understand how each one works. All of the examples we will create in this article, we will use the re.findall() method, which is a built-in method of Python's re module. Let us know about this function first - ... Read More

How to match a single character in python using Regular Expression?

Nikitasha Shrivastava
Updated on 24-Apr-2025 10:46:44

2K+ Views

A single character can be matched in Python using a regular expression. A regular expression is a sequence of characters that helps you find a string or a set of strings using a search pattern. Regular expressions are also known as RegEx. Python provides the re module that is used to work with regular expressions - Using findall() function We use findall() searches for the strings matching the specified pattern in the given string and return all the matches in the form of a list of strings or tuples. Example 1 In the following example, we begin by importing the regular ... Read More

How to convert a list collection into a dictionary in Java?

Nikitha N
Updated on 30-Jul-2019 22:30:21

2K+ Views

Following is an example to convert a list collection into a dictionary in Java.Example Live Demoimport java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; public class CollectionDictionary {    public static void main(String[] args) {       ArrayList list = new ArrayList();       list.add("JavaFx");       list.add("Java");       list.add("WebGL");       list.add("OpenCV");       System.out.println(list);       Dictionary dictionary = new Hashtable();       Hashtable hashTable = new Hashtable();       hashTable.put(1, list.get(0));       hashTable.put(2, list.get(1));       hashTable.put(3, list.get(2));       hashTable.put(4, list.get(3));       System.out.println(hashTable);    } }Output[JavaFx, Java, WebGL, OpenCV] {4=OpenCV, 3=WebGL, 2=Java, 1=JavaFx}

How to copy or clone a Java ArrayList?

Abhinanda Shri
Updated on 25-Feb-2020 09:50:14

2K+ Views

The clone() method of the java.util.ArrayList class returns a shallow copy of this ArrayList instance (i.e the elements themselves are not copied). Using this method, you can copy the contents of one array list to other.Exampleimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String args[]) {       ArrayList arrlist1 = new ArrayList();       arrlist1.add(new StringBuilder("Learning-"));       ArrayList arrlist2 = (ArrayList) arrlist1.clone();       StringBuilder strbuilder = arrlist1.get(0);       strbuilder.append("list1, list2-both pointing to the same StringBuilder");       System.out.println("The 1st list prints: ");       for (int i = ... Read More

How to compare two ArrayList for equality in Java?

Srinivas Gorla
Updated on 30-Jul-2019 22:30:21

14K+ Views

You can compare two array lists using the equals() method of the ArrayList class, this method accepts a list object as a parameter, compares it with the current object, in case of the match it returns true and if not it returns false.Example Live Demoimport java.util.ArrayList; public class ComparingList {    public static void main(String[] args) {       ArrayList list1 = new ArrayList();       list1.add("JavaFx");       list1.add("Java");       list1.add("WebGL");       list1.add("OpenCV");       ArrayList list2 = new ArrayList();       list2.add("JavaFx");       list2.add("Java");       list2.add("WebGL"); ... Read More

How to use remove(obj), remove(index), and removeAll() methods in Java list collections?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:21

224 Views

remove(int index) − Removes the element at position index from the invoking list and returns the deleted element. The resulting list is compacted. That is, the indexes of subsequent elements are decremented by one. removeRange(int fromIndex, int toIndex) − Removes all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. removeAll(Collection c) − Removes from this list all of its elements that are contained in the specified collection (optional operation).

How to iterate over a Java list?

Abhinaya
Updated on 30-Jul-2019 22:30:21

12K+ Views

Often, you will want to cycle through the elements in a collection. For example, you might want to display each element.The easiest way to do this is to employ an iterator, which is an object that implements either the Iterator or the ListIterator interface.Iterator enables you to cycle through a collection, obtaining or removing elements. ListIterator extends Iterator to allow bidirectional traversal of a list and the modification of elements.Before you can access a collection through an iterator, you must obtain one. Each of the collection classes provides an iterator() method that returns an iterator to the start of the ... Read More

Advertisements