- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 34488 Articles for Programming
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
583 Views
GroupingWe group part of a regular expression by enclosing it in a pair of parentheses. This way we apply operators to the group instead of a single character.Capturing Groups and BackreferencesParentheses not only group sub-expressions but they also create backreferences. The part of the string matched by the grouped part of the regular expression, is stored in a backreference. With the use of backreferences we reuse parts of regular expressions. If sub-expression is placed in parentheses, it can be accessed with \1 or $1 and so on.For example, the regex \b(\w+)\b\s+\1\b matches repeated words, such as tahiti tahiti, because the parentheses ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
10K+ Views
The re.groups() methodThis method returns a tuple containing all the subgroups of the match, from 1 up to however many groups are in the pattern. The default argument is used for groups that did not participate in the match; it defaults to None. In later versions (from 1.5.1 on), a singleton tuple is returned in such cases.example>>> m = re.match(r"(\d+)\.(\d+)", "27.1835") >>> m.groups() ('27', '1835')If we make the decimal place and everything after it optional, not all groups might participate in the match. These groups will default to None unless the default argument is given −>>> m = re.match(r"(\d+)\.?(\d+)?", "27") >>> m.groups() ... Read More
![Md Waqar Tabish](https://www.tutorialspoint.com/assets/profiles/518983/profile/60_902902-1663220945.jpg)
903 Views
We can build regular expressions that recognise 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. 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 the previous token. . Angle brackets are ... Read More
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
247 Views
Regex, short for regular expression, is a powerful tool in Python that allows you to perform complex text pattern matching and manipulation. It's like a Swiss Army knife for string handling, enabling you to slice, dice, and reconfigure text with finesse. However, when it comes to matching characters after repetition, a common pitfall awaits the unwary coder. In this article, we'll delve into this challenge, exploring five distinct code examples, each accompanied by a step−by−step breakdown to illuminate the path through this regex thicket. Example We import the 're' module to access regex functionality. The pattern `r'(\d)+(?=x)'` is constructed. ... Read More
![Pranav Indukuri](https://www.tutorialspoint.com/assets/profiles/512605/profile/60_2168928-1662357840.jpeg)
1K+ Views
A single character can be matched in python with using regular expression. Regular expression is a sequence of characters that helps you to find a string or a set of string by using a search pattern. Regular expressions are also known as RegEx. Python provides the re module that is used to work with regular expression. In this article, we will look at how to match a single character in python using regular expression. We use ‘.’ special character to match any single character. Using findall() function In the following example, let us assume ‘oats cat pan’ as a string. ... Read More
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
1K+ 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}
![Abhinanda Shri](https://www.tutorialspoint.com/assets/profiles/13552/profile/60_73264-1512711555.jpg)
1K+ 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
![Srinivas Gorla](https://www.tutorialspoint.com/assets/profiles/13556/profile/60_78057-1512712331.jpg)
12K+ 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
![Ankitha Reddy](https://www.tutorialspoint.com/assets/profiles/13550/profile/60_73963-1512711511.jpg)
140 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).
![Abhinaya](https://www.tutorialspoint.com/assets/profiles/13548/profile/60_54851-1512705920.jpg)
11K+ 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