0
votes
2answers
29 views

lambda function with re.sub in Python 3 [on hold]

-1- What does the below code? part = re.sub('(.{3}).', lambda match: match.group(1), mass, flags=re.DOTALL) -2- What is Python 3 equivalent of the above code snippet? Note, in Python 2 the "mas" ...
0
votes
2answers
23 views

Remove selected text using regular expressions

I have a large html block and I want to remove all <img> elements, but NOT their text parts. So maybe there is something like this: <a href="http:">Some text</a> Some other text ...
1
vote
1answer
10 views

Sleek way of un/commenting out html tags in markdown

I'm trying to find a nice way of wrapping html tags in html comments without writing 5 functions and 50 lines of code. Using an example code : <section class="left span9"> ### Test ...
0
votes
0answers
22 views

How can RegEx named match HTML attributes and ignore order?

I currently have the following RegEx workflow to match WordPress caption tags and subsitute them by Jekyll caption tags: import sys, re def re_sub(pattern, replacement, string): def _r(m): ...
1
vote
1answer
22 views

Convert string to compiled regex matching the exact string

Is there a simple way to transform an exact string matching to a re.compile object ? For example, I would like to mix exact string and regexes.
0
votes
3answers
49 views

Regex matching non-alphanumeric characters

I'm using Python to parse some strings in a list. Some of the strings may only contain non-alphanumeric characters which I'd like to ignore, like this: list = ['()', 'desk', 'apple', ':desk', ...
1
vote
2answers
43 views

Regex to capture numbers up to 2 digits and coma if followed by another word and number

I need a regular expression that matches and return 2 numbers from a string when conditions are met only numbers with a maximum of 2 digits and not greater than 29 (might include a decimal case - so ...
2
votes
2answers
36 views

How to join correctly join words that trails or heads of dashes? - python

I have a list of strings that contains tokens that ends or starts with - I need to join them up such that the words with dashes join up into the correct tokens, e.g. [in]: x = "ko- zo- fond- w- a (* ...
0
votes
1answer
46 views

Regex: If there is a character, then it cannot be a digit

Consider this Python regex for finding phone numbers: reg = re.compile(".*?(\(?\d{3}\D{0,3}\d{3}\D{0,3}\d{4}).*?", re.S) The problem is that this will match any string of digits at least 10 ...
0
votes
1answer
23 views

Chaining re.sub() without breaking previous re.sub() - python

I have a file like this: (a) a. lo mfana (20) Juan - il- -ech (lik) ! EB1: Incwadi [esi-yi-funda-yo: isitshudeni] in-de Papa-wu-rna parlapiya-nyi paja-lkura. b) kupi-Nku Nia taca-mu i. gaan1 fong2 ...
1
vote
1answer
21 views

My re.finditer shows everything when using .group(0), but if I use .group(5) it shows an empty string (python)

I am using this regex patttern in python: '("CDS)(complement)?(\()?(join)?([\(]?[<]?[0-9]{0,6}[.]{0,2}[>]?[0-9]{0,6}[,]?[\)]{0,2})*(/locus_tag=)(["])([^"]*)(["])' To find things in a file, ...
1
vote
1answer
30 views

Nested string replace with regex in Python

I've got a bunch of HTML pages, in which I'd like to convert CSS-formatted text snippets into standard HTML tags. e.g <span class="bold">some text</span> will become <b>some ...
1
vote
1answer
42 views

python replace word as per condition

At standard input, I am providing the following file: #123 595739778 "neutral" Won the match #getin #164 595730008 "neutral" Good girl data#2 looks like this: ...
2
votes
2answers
39 views

How to find a non-alphanumeric character and move it to the end of a string in Python

I have the following string: "string.isnotimportant" I want to find the dot (it could be any non-alphanumeric character), and move it to the end of the string. The result should look like: ...
1
vote
3answers
37 views

Pulling sentences with combinations of keywords in python using regular expressions

Suppose I have the string 'apples are red. this apple is green. pears are sometimes red, but not usually. pears are green. apples are yummy. lizards are green.' and I want to use regular ...
0
votes
1answer
45 views

Unexpected end of regular expression using python

I am trying to scrape stock prices from Yahoo! Finance into a local database as per a tutorial by Chris Reeves, and I keep getting the above error when trying to execute this code. Can anyone tell me ...
0
votes
2answers
67 views

Python test if string matches a template value

I am trying to iterate through a list of strings, keeping only those that match a naming template I have specified. I want to accept any list entry that matches the template exactly, other than having ...
0
votes
2answers
56 views

How to find more than two words in a file using python

I have a file named test.txt. Inside the file test.txt reads: "Drawings me opinions returned absolute in. Otherwise therefore sex did are unfeeling something. Certain be ye amiable by exposed so. ...
0
votes
3answers
35 views

regex group reference error

p = r'([\,|\.]\d{1}$)' re.sub(p, r"\1", v) works, but I want to add a zero to the capture group, not replace with capture group '10', how can I do this? re.sub(p, r"\10", v) fails: Traceback ...
0
votes
4answers
71 views

Alternatives to Python's re.search

I am using re.search to check if a string to text is found in a html page. Sometimes it does not find the string although it is definitely there. For example I would like to find: <div ...
0
votes
3answers
32 views

Python regex optional number match returns more than expected

I have a list of files, and I am trying to filter for a subset of file names that end in 000000, 060000, 120000, 180000. I know I could do a straight string match, but I would like to understand why ...
0
votes
2answers
27 views

Matching html tags with conditional regular expressions

I am trying to use conditional regex to match either <label> or <label title="test"...> My reqular expression is the following: <label(\s?)(?(1)\w+)> From my understanding that ...
1
vote
1answer
35 views

Django urls, diffrent regex?

My urlconf: urlpatterns = patterns('', url(r'^$', 'ping.views.services', name='services'), url(r'^ajax/status/(?P<id>[-\d]+)', 'ping.views.ajx_status', name='ajx_status'), ...
0
votes
1answer
47 views

TypeError: 'int' object is not callable In Python

Bit of a python noob and I'm required to add a regular expression in my code but can not get it to work :/ i have searched the error message on google and tried to figure out whats wrong but no luck ...
0
votes
1answer
29 views

Delete whitespace characters in quoted columns in tab-separated file?

I had a similar text file and got great help to solve it, but I have to realize that I'm too new to programming in general and regex in particular to modify the great Python script below written by ...
2
votes
1answer
28 views

How to parse url parameters in key:value format?

For example i have an url like this: http://www.youtube.com/watch?v=cUjfXWuZySE&list=cUjfXWuZySE. I need to parse its parameters in key:value format. Currently i do it like this params = ...
1
vote
2answers
41 views

I want to match a newline character followed by a string using regular expression in python

Device ID: xyz Entry address(es): IP address: 10.3.10.46 Platform: WS-x, Capabilities: Switch IGMP Interface: GigabitEthernet9/33, Port ID (outgoing port): GigabitEthernet0/2 Holdtime : 177 sec ...
2
votes
3answers
44 views

regex does not work if I read a string from a file

I have a file named foo with the following text <ca> -----BEGIN CERTIFICATE----- MIIB6DCCAVECBCMBFpQwDQYJKoZIhvcNAQEFBQAwOzEPMA0GA1UEAxMGbGZ0Lmpw ...
0
votes
1answer
22 views

A regular expression in BeautifulSoup 4

I need to find element with 'random' id in html. My code is look like: from bs4 import BeautifulSoup import re soup = BeautifulSoup(html) print soup.find(id="id_123456_name") 123456 - may changes ...
0
votes
1answer
31 views

regex match whole line instead of between the tag

I am new to regex and just testing it out, my problem is after looking at examples my regex is matching the whole line almost instead of in between the tag. re.findall(r'<i>(.*)</i>', ...
1
vote
3answers
38 views

How to automatically find pattern like 'c++' in string using python re module?

Now I have a list of pattern: patterns = ['php', 'java', 'c++'] and I want to match it in another string, say, r'c++ primer'. I want to use python re module to do it, but the problem is, if I use: ...
1
vote
2answers
39 views

Using python's RegEx {m,n} operation, but using variables for m and n

I want to specificy a global min and max variable to use in a regular expression checking ID validity. For example, set variables min=8 max=16 alphanumeric input Then the expression I want ...
-1
votes
1answer
32 views

Python, regex: Nested parenthesis [duplicate]

Suppose I have a string: string = (L^M=>P)^(B^L=>M)^(C) I want to get individual clauses, and this is what I did: match = re.search('(\([^()]*\))\^(\([^()]*\))', string) print match.groups() ...
0
votes
2answers
57 views

Python regex: overlapping patterns

Suppose I have a string: string = 'AvBvC' I want to match A, B, and C, and this is what I did: match = re.search('(.*)v(.*)', string) print match.groups() The problem is, the result shows that: ...
0
votes
1answer
34 views

Python regex: matching nested parenthesis [duplicate]

suppose I have a string containing substrings # the substrings and the whole string surrounded by parenthesis string = '((substring1)(substring2))' I want to get both substring1 & substring2 ...
0
votes
4answers
32 views

extracting image file name from the web [on hold]

I am trying to scrape image information from the web and I am wondering if there is any way for me to extract the image file name. For instance if the following HTML expression is stored within the ...
1
vote
2answers
33 views

Python Regular Expressions re.findall — split a string into two

I have strings like this: "C BOS - Traded from Royal Disappointments" And I want to split them into everything before the dash, and everything after. So simply in two variables, new1 and new2, I ...
0
votes
0answers
44 views

C++/Python/awk analysis of trace file [on hold]

I have generated a trace file using my tcl script but I need an analysis script to filter out everything in the trace file except CBR traffic packets and I finally need number of packets sent, ...
2
votes
2answers
56 views

Python Regex either or case [on hold]

I have a small module that gets the lemma of a word and its plural form. It then searches through sentences looking for a sentence that contains both words (singular or plural) in either order. I have ...
0
votes
3answers
37 views

Finding and combining acronyms in Python

I am trying to process some tweets, and I am trying to split up certain terms in the tweets as follows : word : DailyRX final_word : Daily R X word : AdeleOfficial final_word : Adele Official word ...
0
votes
1answer
39 views

negative lookbehind regex assertion in python

I am working on an application that has a search feature, in which I want to match the search patterns. The patterns can have the following forms: search:'pattern' and search:"pattern" (quoted ...
1
vote
4answers
26 views

Python regex replace space from string if surrounded by numbers, but not letters

My input variants as strings: '12345 67890' 'abc 123' '123 abc' 'abc def' My aim is to remove the space if found between the characters if characters from both sides are digits, but not letters. I ...
1
vote
2answers
36 views

Using python regular expression to match times

I'm trying to parse a csv file with times in the form of 6:30pm or 7am, or midnight. I've googled around and read the docs for regular expressions in the python docs but haven't been able to implement ...
2
votes
1answer
52 views

Looking for a good way to split a string on all-capital words

For example I have an arbitrary string: var = 'I have a string I want GE and APPLES but nothing else' What's the best way to split the string in python so that I can obtain just 'GE' and 'APPLES'. ...
1
vote
2answers
38 views

Python regular expressions repeated sequence of decimal number followed by whitespaces

A quick quiz, should be a no brainer: I want to be able to match strings of the following kind : 1323 323 434 i.e. a decimal number, followed by some white space and this repeated as many times ...
2
votes
2answers
26 views

Negative Lookahead matching

I have this string: maria 10 years maria 10 maria10 maria10 years And would like to match maria followed by 10 when the next word is not years. I tried like this: \maria\s?[0-9]+(?!years) But ...
2
votes
2answers
50 views

How to use positive lookbehind with If-Then-Else regex in Python

I'm trying to combine a positive lookbehind with the If-Then-Else syntax for regex in Python. What I'm trying to do is parse through some data and I need to use two different markers to split the ...
6
votes
4answers
21k views

Python string match

If a string contains *SUBJECT123, how do I determine that the string has subject in it in python?
11
votes
4answers
15k views

How to use re match objects in a list comprehension

I have a function to pick out lumps from a list of strings and return them as another list: def filterPick(lines,regex): result = [] for l in lines: match = re.search(regex,l) ...
2
votes
4answers
4k views

regular expression matching everything except a given regular expression

I am trying to figure out a regular expression which matches any string which doesn't start with mpeg. A generalization of this is matching any string which doesn't start with a given regular ...

15 30 50 per page