Found 33676 Articles for Programming

How to convert a single character to its integer value in Python?

Sakshi Rayu
Updated on 02-May-2025 19:46:40

885 Views

In Python, the ord() function converts a given character to the corresponding ASCII (American Standard Code for Information Interchange) integer. The ord() function raises a TypeError if you pass a string value as a parameter. Converting a single alphabet to its integer In the following example, we have converted a character 'A' into its Unicode using the ord() function - my_str='A' result=ord(my_str) print("Unicode of 'A'-", result) Following is an output of the above code - Unicode of 'A'- 65 Printing Integer values of all the alphabets We can use the ord() function to print all the Unicode characters ... Read More

How we can create a dictionary from a given tuple in Python?

Pythonista
Updated on 25-Feb-2020 11:14:12

430 Views

We can use zip() function to produce an iterable from two tuple objects, each corresponding to key and value items and then use dict() function to form dictionary object>>> T1=('a','b','c','d') >>> T2=(1,2,3,4) >>> dict((x,y) for x,y in zip(t1,t2))Dictionary comprehension syntax can also be used to construct dictionary object from two tuples>>> d={k:v for (k,v) in zip(T1,T2)} >>> d {'a': 1, 'b': 2, 'c': 3, 'd': 4}

How to extract a group from a Java String that contains a Regex pattern

Arnab Chakraborty
Updated on 21-Jun-2020 06:30:13

311 Views

How to extract a group from a Java String that contains a Regex patternimport java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexTest {    public static void main(String[] args) {       Pattern pattern = Pattern.compile("fun");       Matcher matcher = pattern.matcher("Java is fun");       // using Matcher find(), group(), start() and end() methods       while (matcher.find()) {          System.out.println("Found the text \"" + matcher.group()             + "\" starting at " + matcher.start()             + " index and ending at index ... Read More

How to capture multiple matches in the same line in Java regex

Arnab Chakraborty
Updated on 20-Jun-2020 10:49:20

3K+ Views

Exampleimport java.util.regex.*; class PatternMatcher {    public static void main(String args[]) {       int count = 0;       // String to be scanned to find the pattern.       String content = "aaa bb aaa";       String string = "aaa";       // Create a Pattern object       Pattern p = Pattern.compile(string);       // get a matcher object       Matcher m = p.matcher(content);       while(m.find()) {          count++;          System.out.println("Match no:"+count);         ... Read More

Search and Replace with Java regular expressions

Sravani S
Updated on 26-Feb-2020 08:09:33

1K+ Views

Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn.A regular expression is a special sequence of characters that help you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data.The replaceFirst() and replaceAll() methods replace the text that matches a given regular expression. As their names indicate, replaceFirst replaces the first occurrence, and replaceAll replaces all occurrences.ExampleLive Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexMatches { ... Read More

Regular Expressions syntax in Java Regex

Jai Janardhan
Updated on 30-Jul-2019 22:30:21

282 Views

Following is a simple program demonstrating how to use regular expression in Java. Java Regex Characters

Regex named groups in Java

George John
Updated on 30-Jul-2019 22:30:21

293 Views

Java Regex Capturing Groups

Named Capturing groups in Java Regex

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

191 Views

Java Regex Capturing Groups

Capturing groups and back references in Java Regex

Moumita
Updated on 25-Feb-2020 07:11:20

1K+ Views

Capturing groups are a way to treat multiple characters as a single unit. They are created by placing the characters to be grouped inside a set of parentheses. For example, the regular expression (dog) creates a single group containing the letters "d", "o", and "g".Capturing groups are numbered by counting their opening parentheses from the left to the right.In the expression ((A)(B(C))), for example, there are four such groups -((A)(B(C)))(A)(B(C))(C)Back references allow repeating a capturing group using a number like \# where # is the groupnumber. See the example below −ExampleLive Demoimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Tester {   ... Read More

How do I use capturing groups in Java Regex?

Paul Richard
Updated on 30-Jul-2019 22:30:21

139 Views

https://www.tutorialspoint.com/javaregex/javaregex_capturing_groups.htm

Advertisements