Search and Replace in Python

Mohd Mohtashim
Updated on 30-Jan-2020 07:32:26

330 Views

One of the most important re methods that use regular expressions is sub.Syntaxre.sub(pattern, repl, string, max=0)This method replaces all occurrences of the RE pattern in string with repl, substituting all occurrences unless max provided. This method returns modified string.Example Live Demo#!/usr/bin/python import re phone = "2004-959-559 # This is Phone Number" # Delete Python-style comments num = re.sub(r'#.*$', "", phone) print "Phone Num : ", num # Remove anything other than digits num = re.sub(r'\D', "", phone) print "Phone Num : ", numOutputWhen the above code is executed, it produces the following result −Phone Num : 2004-959-559 Phone Num : 2004959559Read More

Matching Versus Searching in Python

Mohd Mohtashim
Updated on 30-Jan-2020 07:31:11

1K+ Views

Python offers two different primitive operations based on regular expressions: match checks for a match only at the beginning of the string, while search checks for a match anywhere in the string (this is what Perl does by default).Example Live Demo#!/usr/bin/python import re line = "Cats are smarter than dogs"; matchObj = re.match( r'dogs', line, re.M|re.I) if matchObj:    print "match --> matchObj.group() : ", matchObj.group() else:    print "No match!!" searchObj = re.search( r'dogs', line, re.M|re.I) if searchObj:    print "search --> searchObj.group() : ", searchObj.group() else:    print "Nothing found!!"OutputWhen the above code is executed, it produces the following ... Read More

Search Function in Python

Mohd Mohtashim
Updated on 30-Jan-2020 07:30:15

3K+ Views

This function searches for first occurrence of RE pattern within string with optional flags.SyntaxHere is the syntax for this function −re.search(pattern, string, flags=0)Here is the description of the parameters −Sr.No.Parameter & Description1patternThis is the regular expression to be matched.2stringThis is the string, which would be searched to match the pattern at the beginning of string.3flagsYou can specify different flags using bitwise OR (|). These are modifiers, which are listed in the table below.The re.search function returns a match object on success, none on failure. We use group(num) or groups() function of match object to get matched expression.Sr.No.Match Object Method & Description1group(num=0)This method returns entire match ... Read More

Define Measurement in Screen Pixels with CSS

mkotla
Updated on 30-Jan-2020 07:27:48

197 Views

To define a measurement in screen pixels with CSS, use the px unit.Let us see an example:                            This div has relative positioning.          

Using CONCAT_WS Function with MySQL WHERE Clause

Sharon Christine
Updated on 30-Jan-2020 07:26:58

451 Views

When we use CONCAT_WS() function with WHERE clause then the output would be based upon the condition provided in WHERE clause. It can be understood from the example of ‘Student’ table as followsExamplemysql> Select CONCAT_WS(' ',Name, Last_name, 'Resident of', Address, 'is studying', Subject)AS 'Student Detail' from student WHERE id = 20; +----------------------------------------------------------------+ | Student Detail                                                 | +----------------------------------------------------------------+ | Gaurav Rathore Resident of Jaipur is studying Computers        | +----------------------------------------------------------------+ 1 row in set (0.00 sec)

Descendent Selectors in CSS

Samual Sam
Updated on 30-Jan-2020 07:25:02

505 Views

Suppose you want to apply a style rule to a particular element only when it lies inside a particular element. As given in the following example, style rule will apply to element only when it lies inside tag.ul em {    color: #FFFF00; }Suppose now for element and style rule applied to :ol strong {    color: #808000; }

Type Selectors in CSS

varma
Updated on 30-Jan-2020 07:24:30

1K+ Views

A selector is an HTML tag at which a style will be applied. This could be any tag like or etc.With the type selector, set for HTML tags like h1, h2, h3, p, etc:h2 {    color: #FF0000; }Set for p:p {    color: #800000; }

What is a Selector and How It Is Used in CSS

Lakshmi Srinivas
Updated on 30-Jan-2020 07:23:49

496 Views

A selector is an HTML tag at which a style is applied. This could be any tag like or etc.The following figure describes what a Selector is:Let us see an example of Type Selector, to set color:h1 {    color: #36CFFF; }

Base Overloading Methods in Python

Mohd Mohtashim
Updated on 30-Jan-2020 07:22:55

457 Views

Following table lists some generic functionality that you can override in your own classes −Sr.No.Method, Description & Sample Call1__init__ ( self [,args...] )Constructor (with any optional arguments)Sample Call : obj = className(args)2__del__( self )Destructor, deletes an objectSample Call : del obj3__repr__( self )Evaluable string representationSample Call : repr(obj)4__str__( self )Printable string representationSample Call : str(obj)5__cmp__ ( self, x )Object comparisonSample Call : cmp(obj, x)

Style Rules in CSS

Sreemaha
Updated on 30-Jan-2020 07:22:37

6K+ Views

CSS comprises of style rules interpreted by the browser and then applied to the corresponding elements in your document. A style rule is made of three parts −Selector -  A selector is an HTML tag at which a style will be applied. This could be any tag like or etc.Property - A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color, border etc.Value - Values assigned to properties. For example, the color property can have value either red or #F1F1F1 etcYou can put CSS Style Rule Syntax as ... Read More

Advertisements