Found 26504 Articles for Server Side Programming

How to divide a string by line break or period with Python regular expressions?

Rajendra Dharmkar
Updated on 16-Dec-2019 08:57:39

383 Views

The following code splits given string by a period and a line break as followsExampleimport re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.]+', s) print resultOutputThis gives the following output['Hi', "It's nice meeting you", 'My name is Jason']

How can I match the start and end in Python\\\'s regex?

Niharikaa Aitam
Updated on 08-Jun-2025 11:22:07

2K+ Views

In Python, the re module is used to work with regular expressions. In some cases, we need to check whether a string starts or ends with a specific pattern, and then we need to use special regex characters called anchors. Following are the anchors used in regular expressions - ^ − This anchor matches the beginning of a string. $ − This anchor matches the end of a string. Python Regex Methods The following methods from the re module are commonly used to apply start and end matching - ... Read More

How do I do a case-insensitive string comparison in Python?

Niharikaa Aitam
Updated on 10-Jun-2025 16:37:19

4K+ Views

In Python, string comparisons are case-sensitive by default. For example, when we consider the strings "Hello" and "hello" then they are considered as two different strings because of the difference in their letter casing.  Case-insensitive String Comparison in Python In some tasks, such as searching user input, comparing filenames, or processing natural language, it's important to compare strings without considering case differences. To perform string comparison in Python, we have several built-in methods such as lower(), upper(), and casefold(), which help us to normalize the casing of strings before comparing them. ... Read More

How to search and replace text in a file using Python?

SaiKrishna Tavva
Updated on 05-Mar-2025 17:39:07

16K+ Views

File manipulation is a fundamental aspect of programming, especially when dealing with data processing and management. Python offers powerful tools for handling files and text efficiently. A common task is searching for specific text patterns within a file and replacing them with desired content. This article explores several practical methods for searching and replacing text in a file using Python. Basic Text Replacement Let's start with a simple example of searching for a specific word in a file and replacing it with another word. In this particular example, we'll search for the word "old" and replace it with "new" − ... Read More

What is the difference between ++i and i++ in c?

Jayashree
Updated on 12-Sep-2023 02:57:07

38K+ Views

In C, ++ and -- operators are called increment and decrement operators. They are unary operators needing only one operand. Hence ++ as well as -- operator can appear before or after the operand with same effect. That means both i++ and ++i will be equivalent.i=5; i++; printf("%d", i);and i=5 ++i; printf("%d", i);both will make i=6.However, when increment expression is used along with assignment operator, then operator precedence will come into picture. i=5; j=i++;In this case, precedence of = is higher than postfix ++. So, value of i is assigned to i before incrementing i. Here j becomes 5 and i becomes 6.i=5; ... Read More

What is the difference between Python\\'s re.search and re.match?

Niharikaa Aitam
Updated on 09-Jun-2025 09:47:04

2K+ Views

In Python, Regular expressions are also called RegEx, which is a sequence of characters that defines a search pattern. The re module provides several functions to work with patterns in text. This is widely used in Python tasks such as string matching, validation, and manipulation. The most commonly used functions in the "re" module are re.match() and re.search(). These two methods are used to check for the presence of a pattern, but they differ in the way they look for a pattern match within a string. In this article, we are going to see the difference between the Python re.search() ... Read More

What is the match() function in Python?

SaiKrishna Tavva
Updated on 01-Sep-2025 15:00:48

18K+ Views

When we are working with string data in Python, it's sometimed necessary to check if certain patterns appear in a string. Python's re module contains many methods which are used for pattern matching in the given strings using regular expressions. What is match() function? The match() function in re module is used in the scenarios such as validating structured input, checking prefixes or extracting information from well-defined formats such as phone numbers or dates. Syntax Following is the syntax of using the match() function in Python - re.match(pattern, string, flags=0) Where, pattern: The regular ... Read More

What is the simplest way to SSH using Python?

Niharikaa Aitam
Updated on 07-Jun-2025 22:28:13

6K+ Views

SSH is referred as secure shell which is useful to remotely manage computers in a secure manner. To connect to a server, we typically use PuTTy, MobaXTerm or the command-line ssh application. Every Unix, Linux and Mac server includes SSH as standard equipment and it is usable in every data centre. SSH connections have made it feasible for secure remote access to resources, remote command execution, the transmission of software patches and updates and other administrative or management tasks. SSH is used in systems administration and file transfer software as well as to handle routers, server hardware, virtualization platforms and ... Read More

How to perform different commands over ssh with Python?

Niharikaa Aitam
Updated on 20-Jun-2025 19:15:44

2K+ Views

When we want to remotely access and execute commands on another machine then we use the paramiko library in Python. Paramiko is a third-party library that is used to connect and communicate securely with remote machines using the SSH, i.e., Secure Shell protocol. It allows us to execute commands, transfer files, and perform other remote tasks programmatically. To use the Paramiko library, first we need to install it in our local system using the below command - pip install paramiko Example Following is the example, in which we connect to a remote server via SSH and perform multiple shell ... Read More

How to use FTP in Python?

SaiKrishna Tavva
Updated on 13-Nov-2024 12:47:27

482 Views

In Python we can use FTP (File Transfer Protocol) by importing the ftplib module, it will provide a simple interface to access FTP servers to retrieve files and process them locally. ftplib module allows us to write Python programs that perform a variety of automated FTP tasks. Objectives of FTP The objectives of FTP are as follows FTP provides file sharing. FTP helps us to encourage the use of remote computers. FTP is used to transfer the data reliably and efficiently. Some Common tasks we can perform using FTP in Python by utilizing the 'ftplib' module are as follows: ... Read More

Advertisements