Python get string between two slashes
I am very new to python, i am trying to write a script which opens a file, read the file do some custom function for me and store it in project location. Meanwhile i am facing trouble to read the file line by line and find the string in between the two forward slashes. like in the example shown below i want the script to read the "string between the slashes". "element / read_this_string /... " I did go through some hints provided online, as in to use Regular expression or use split function. I found split() rather easy to implement. I would really appreciate if someone could help me with this problem i am stuck with. I am sure its a simple one but i am wasting too much time on this. asked Jan 29, 2016 at 16:29
4 You can pass a delimiter to split, to clean the spaces you can them use the strip method..
answered Jan 29, 2016 at 16:37
canesincanesin 1,8672 gold badges17 silver badges30 bronze badges To open a file in python, you can use python's with statement, which will handle file closing. and the for loop will take care of reading the file line by line.
answered Jan 29, 2016 at 16:38
3 Python Programmings = 'canada/japan/australia' l = s.split('/') print(l) Output ['canada', 'japan', 'australia'] Check if given String is Palindrome in Python Cutting and slicing strings and examples of substring Convert String variable into float, int or boolean Convert Camel Case to Snake Case and Change Case of a particular character in a given string Reverse a string in different ways Generate random string of N characters How do I trim white space in Python? Different ways to pad or add zeroes to string How to check if the string is empty or blank? Different ways to count the number of occurrences of a character in a string How to check if string ends with one of the strings from a list? How to Split Strings on Multiple Delimiters or specified characters? How do I append one string to another? How do I iterate over a string in Python? How to strip punctuation from a string in Python? How to convert a list into string? How to convert JSON into String? How to compare strings in Python? How to check whether a string starts with XXXX in Python? How to sort a list of strings? Different ways to mesh or interleave two strings together in Python How do I compare two strings in Python? How to compare two string with some characters only in Python? Why does comparing strings using either '==' or 'is' sometimes produce a different result? How to compare individual characters in two strings in Python? How can the indices of a string be compared for equality in Python? How to compare a string with a Enum in Python? String comparison in Python is vs == Comparing characters in a string in Python Python compare two strings and check how many chars they have in common How to check if a variable is equal to one string or another string? Python compare two strings retain difference from one end Checking if two strings contain the same characters in Python Find the position of difference between two strings How can I check if a string has the same characters in Python? How to check if two strings contain same letters and numbers in Python? How to use string.replace() in Python? How to replace multiple substrings of a string in Python? How to replace the first character alone in a string in Python? How to replace specific instance of string in string in Python? Python to replace strings starting from the end? Concatenate strings in multiline in Python Replacing a character from a certain index in Python? Python string replace multiple occurrences Python string replace character How to concatenate a fixed string and a variable in Python How to concatenate two variable one is string and other is int in Python? Concatenate strings and variable values in Python Append several variables to a list in Python How can I concatenate str and int objects? TypeError: cannot concatenate 'str' and 'float' objects Python How to remove leading and trailing spaces in Python? How do I trim whitespace in Python? Trim specified number of spaces from left and right in Python? Trim specific leading and trailing characters from a string in Python How do I strip all leading and trailing punctuation in Python? How to remove leading and trailing zeros in a string in Python? Remove last character if it's a backslash in Python How to capitalize a string in Python? How to change a string into uppercase in Python? How can I capitalize the first letter of each word in a string in Python? Capitalize a string in Python Randomly capitalize letters in string in Python Capitalize first letter of the first word in a list in Python How do I lowercase a string in Python? Convert UPPERCASE string to sentence case in Python Change some lowercase letters to uppercase in string in Python Check if string is upper, lower, or mixed case in Python How to capitalise last letter of string in Python? How to capitalize first and last letters of line in a Python string? How to capitalize every 3rd letter of string in Python? Capitalizes a string according to the Index positions in Python Capitalise every second letter in a string in Python? Extract Uppercase and Lowercase characters from String Python? Count number of Uppercase and Lowercase characters in String in Python? How to get the size of a string in Python? How to get size of string in bytes in Python How can I fill out a Python string with spaces? How to pad with n characters in Python? Python padding strings of different length Python String Padding How to pad a numeric string with zeros to the right in Python? How to pad zeroes to a string? How to pad a string with leading zeros in Python3? Dynamically calculated zero padding in format string in python Format integer as string with leading zeros in Python? Python string formatting padding negative numbers How to add X number of spaces to a string in Python Display string multiple times in Python Python - How to add space on each 4th character? Paragraph formatting in Python Python regex add space whenever a number is adjacent to a non-number How can I add space between parentheses and string in Python? Add space between number and string in Python Python string formatting fixed width How to replace all characters in a string with one character in Python? Find a whole word is in given string in Python? Python pad string to fixed length Python pad string with zeros Efficient way to add spaces between characters in a string in Python How to get the position of a character in Python? How to find all positions of a character in a string in Python? Find a substring in a string and returning the index of the substring in Python How to find all occurrences of a substring? Example of string find in Python Python Find pattern in a string Find index of last occurrence of a substring in a string in Python Python find first occurrence of character after index How to find all the indexes of all the occurrences of a word in a string in Python? Python split string into multiple string Split string on backslash in Python Splits the string at every underscore and stop after the Nth position How to split a string into an list of characters in Python? Split string into two parts only in Python Split a string only by first space in Python Split string in Python to get first value? Split a string on the last occurrence of the delimiter in the string in Python Split a string by the position of a character in string in Python Split string into strings by length in Python Split string on forward slash in Python Python split on newline How to split string without losing split character in Python? Split on non alpha-numeric and keep the separators in Python Splitting a string with multiple delimiters in Python Split string only after double quotes in Python How to split a byte string into separate bytes in Python? Split a string at the words AND OR NOT keeping the separators How can I find the first occurrence of a sub-string in a Python string? How to split a string by multiple punctuations with Python? Split string on punctuation Split Strings into words with multiple word boundary delimiters Python count number of string appears in given string Python center align the string using a specified character Check if the string ends with given string or character in Python Python set the tab size to the specified number of whitespaces Check if all the characters in string are digits in Python Find last business or working day of a month in Python Follow @Pythonblogging PYTHON TUTORIAL Variables If…Else While Loop For Loops Lists Dictionary Tuples Classes and Objects Inheritance Method Overriding Operator Overloading NumPy PYTHON EXAMPLES Basic Date Time Strings Pandas Matplotlib NLP Object Oriented Programming Twitter Data Mining TensorFlow BASIC Introduction and Installation Hello World Tensors Tensor Calculations Computation Graph Variables ©2017-20 PythonProgramming.in Drop us a line To top |