Found 27104 Articles for Server Side Programming

How to pass JavaScript variables to PHP?

Johar Ali
Updated on 30-Jul-2019 22:30:21

19K+ Views

You can easily get the JavaScript variable value on the same page in PHP. Try the following codeL. var res = "success";

How to write Python regular expression to get zero or more occurrences within the pattern?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:20:19

377 Views

*      An asterisk meta-character  in a regular expression indicates 0 or more occurrences of the pattern to its leftThe following code matches and prints the zero or more occurrences of the pattern '\w' in the string 'chihua huahua'Exampleimport re s = 'chihua huahua' result = re.findall(r'\w*', s) print resultOutputThis gives the output['chihua', '', 'huahua', '']

What Python regular expression can be used in place of string.replace?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:08:42

65 Views

The following code replaces all the characters from given string with ''Exampleimport re line = 'this is a text with in between and then there are instances ... where the number ranges from 0-99.\ and there are many other lines in the text files \ with such tags ' line = re.sub(r"", "", line) print lineOutputThis gives the outputthis is a text with in between and then there are instances ... where the number ranges from 0-99.and there are many other lines in the text files with such tags

How does B regular expression work in Python?

Rajendra Dharmkar
Updated on 16-Jun-2020 11:54:00

452 Views

The word boundary \b matches positions where one side is a word character (usually a letter, digit or underscore)\B matches all positions where \b doesn't match.The following code shows how regexpr \B worksimport re result = re.findall(r'\Bcat', 'certificate') result2 = re.findall(r'\Bcat', 'tomcat') result3 = re.findall(r'\Bcat', 'catfish') print result, result2,result3This gives the output['cat'] ['cat'] []

How you can get a true/false from a Python regular expressions?

Rajendra Dharmkar
Updated on 16-Jun-2020 11:43:03

3K+ Views

When you use match and search methods of module re, if there is a match, it has bool value of True and if there is no match, you get None that has a bool value of False.Match objects are always true, and None is returned if there is no match>>> bool(re.search("def", "abcdefgh")) True >>> bool(re.search("rest", "pqrstuv")) False

How does [d+] regular expression work in Python?

Rajendra Dharmkar
Updated on 08-Sep-2023 13:12:32

2K+ Views

Regular expressions are an essential tool for searching and manipulating strings in Python. Among the various patterns and techniques available, the [d+] expression is particularly useful for matching one or more digits in a string. In this article, we will explore the [d+] regular expression pattern, its usage, and provide five code examples with step−by−step explanations to help you understand and apply this concept in your Python projects. Before diving into the code examples, let's first understand the [d+] pattern. [d+] is a combination of two elements: [d]: This is a shorthand character class for the digits 0 to 9. ... Read More

How to write a case insensitive Python regular expression without re.compile?

Rajendra Dharmkar
Updated on 03-Nov-2023 02:49:54

10K+ Views

We can pass re.IGNORECASE to the flags parameter of search, match, or sub −Example import re print (re.search('bush', 'BuSh', re.IGNORECASE)) print (re.match('bush', 'BuSh', re.IGNORECASE)) print (re.sub('bush', 'xxxx', 'Bushmeat', flags=re.IGNORECASE))Output xxxxmeat

Extract decimal numbers from a string in Python

Pranav Indukuri
Updated on 03-Nov-2023 02:48:14

10K+ Views

To extract decimal numbers from a string in Python, regular expressions are used. A regular expression is a group of characters that allows you to use a search pattern to find a string or a set of strings. RegEx is another name for regular expressions. The re module in Python is used to work with regular expressions. In this article, we will get to know how to extract decimal numbers from a string in python using regular expressions. We use \d+\.\d+ regular expression in python to get non digit characters from a string. Where, \d returns a match where ... Read More

How to check if a list is empty in Python?

Vikram Chiluka
Updated on 23-Aug-2023 13:12:10

56K+ Views

In Python, a list is an ordered sequence that can hold several object types such as integer, character, or float. In this article, we will show you how to check if the given input list is an empty list or NOT using python. Below are the 5 methods to accomplish this task − Using not operator Using len() function By Comparing with an Empty List Using __len__() Using NumPy Module Assume we have taken an empty list. We will check if the input list is empty or not and returns some random message for acknowledgment using different methods ... Read More

How do make a flat list out of list of lists in Python?

Pranav Indukuri
Updated on 08-Nov-2022 12:15:33

247 Views

A nested list is a list which has elements as lists itself. For example: [[1, 2, 3], [4, 5, 6], [7, 8, 9]] is a nested list as it has 3 lists ([1, 2, 3], [4, 5, 6], and [7, 8, 9]) as its elements. To flatten a list of lists (nested list) i.e., to convert a 2D list into a 1D list, there are different ways such as nested for loop, list comprehension, built-in functions or by importing libraries in python. In this article we will discuss the above methods to flatten a list in Python. Using for loops ... Read More

Advertisements