Questions tagged [re-python]

re-python tag is used for the question in python that are related to regular expression. re-python comes from the 're' module that python has for regular expressions.

re-python tag is used for the question in python that are related to regular expression. re-python comes from the 're' module that python has for regular expressions. A regular expression is a special sequence of characters that helps you match or find other strings or sets of strings, using a specialized syntax held in a pattern. Regular expressions are widely used in UNIX world.

The module re of python provides full support for Perl-like regular expressions in Python. The re module raises the exception re.error if an error occurs while compiling or using a regular expression.

The question that are related to regular expressions and coded in python can use the tag re-python in there question.

12 questions
1
vote
1 answer

Trying to replace image extensions like "." to "_resized."

I'm trying to use this code in Python using regular expression to get all the image files (of types jpg, png and bmp) in my current folder and add a word "resized" inbetween the filename and the extension Input Batman - The Grey Ghost.png Mom and…
1
vote
1 answer

Regex words extraction within a string store it into a python list

I am new to regex, I want to extract specific words within a python string. This is the string: '1. feature name: occupation_Transport-moving
coefficient: 0.1776
2. feature name: education
coefficient: 0.0726
3. feature name:…
stern15
  • 37
  • 4
1
vote
1 answer

Regex for letters having constant alphabetical distance between them

I'm trying to match words with letters that have some constant alphabetical distance between them, for example, I'd like to find all words with A.*B, B.*C, C.*D, etc. I'm currently using the 're' package in Python 3. Is there some way to do this…
Shay
  • 11
  • 1
1
vote
1 answer

How regular expression handles `^` or `$` in the middle of regex pattern?

I am trying to play with regular expressions in python. I have framed regular expression as given below. I know that ^ is used to match at the beginning of search string. I have framed by match pattern which contains multiple ^, but I am not sure…
Mangu Singh Rajpurohit
  • 10,806
  • 4
  • 68
  • 97
0
votes
1 answer

Please explain how re module works in this case, re.sub() and re.findall seem to give different matches

I'm learning RegEx in Python and have faced this problem. Assume I have a variable called s: >>>print(repr(s)) 'HTML elements include\n\n* headings\n* paragraphs\n* lists\n* links\n* and more\n\nTry it!!!' I want to match '* headings\n*…
Khai Hoan Pham
  • 86
  • 1
  • 2
  • 7
0
votes
1 answer

Regex - find all whitespaces and ignore hyphen separated words in multiline string

I want to create a regex pattern which finds whitespaces and ignore hyphen seperated words. The basic rule is to find any subsequent whitespaces([\s]+), and do not find whitespaces where the pattern is: [\S]+-[\s]+[\S]+ (The pattern of which i…
Montoya
  • 2,819
  • 3
  • 37
  • 65
0
votes
1 answer

python - Re module leaving space for matched string

I am using re module in python to remove occurence of certain string. Below is what I am trying: >>> import re >>> t = re.sub(re.compile('ab'), "", 'This is a ab text') >>> t 'This is a text' Note that in above instead of replacing 'ab' with ''…
snow_leopard
  • 1,466
  • 2
  • 20
  • 36
0
votes
0 answers

Reading multiple lines at once from a file in python for regex matching

I have a log file in while I want to search for a pattern involving multiple lines using regular expression. From what I know, I am able to read and match only one line at once. How do I load a whole file in memory and do pattern matching? I have a…
0
votes
0 answers

Maintaining the particular special character/s after/before a word while doing re.sub in Python

I am trying to replace a word using re.sub in python. The format is re.sub(pattern, replacement,string) Lets consider the following snippet of code sentence = "I want to replce this sentence" pattern = "replce" replacement =…
Saurav Mukherjee
  • 177
  • 1
  • 16
0
votes
0 answers

Regular expression to detect table names in oracle code

I would like to detect which tables are used to get data from in procedure and function code in oracle. ... from ; ... from ; ... from where ...; ... from (, )*…
JaviOverflow
  • 1,434
  • 2
  • 14
  • 31
0
votes
1 answer

Python regex: how to achieve this complex replacement rule?

I'm working with long strings and I need to replace with '' all the combinations of adjacent full stops . and/or colons :, but only when they are not adjacent to any whitespace. Examples: a.bcd should give abcd a..::.:::.:bcde.....:fg should give…
Vanni Rovera
  • 128
  • 3
  • 12
-2
votes
2 answers

Should I use regex or something else to extract log id from log files?

I have list with the following data: ["asdf mkol ghth", "dfcf 5566 7766", "7uy7 jhjh ffvf"] I want to use regular expressions in python to get a list of tuples like this [("asdf", "mkol ghth"),("dfcf", "5566 7766"),("7uy7", "jhjh ffvf")] I tried…
Learner
  • 19
  • 7