Tagged Questions
0
votes
2answers
24 views
Filterig/removing/excluding private IPs with port from a nested list
What:
Python 2.7 is being used.
I am using the virustotal API to generate a list of IP's, in list format. When I run type() on the object, it returns list. At the bottom is an example of the data. Is ...
0
votes
4answers
44 views
Regular Expression for numbers and letters but not only numbers
I have this string :
S3UPLOAD:Uploading file: /var/mobile/Applications/999445D0-5B4D-4078-9B81-4F65D3474971/Documents/2014-08-25 Driving 22.58.39/2014-08-25 Driving 22.58.39.vmd.zip 783:00
I would ...
-1
votes
3answers
43 views
Pythonic Way to Add Space Before Capital Letter If and Only If Previous Letter is Not Also Capital
As the title says, I would like to add spaces before capital letters, but only if the prior letter is not also a capital letter. So 'HelloCHARLIE this isBob.' should become 'Hello CHARLIE this is ...
-2
votes
1answer
47 views
Spliting strings surrounded by special characters
I have an input that looks like the following.
word1-word2
word1 word2
word1+word2
--word1--word2-
word1-word2
word1,word2,
(word1),word2
etc
I have to create a list that finally has ...
0
votes
4answers
48 views
Python Regex best delimiter to use?
I'm trying to parse a line using re.split in python. Here is an example line I am trying to work on:
drwxr-xr-x 2 user1 user1 4096 Sep 4 14:23 FolderName
drwxr-xr-x 2 user1 user1 ...
1
vote
1answer
20 views
Using fnmatch to match 2 parts of a file name
I am currently using fnmatch to find the files that I want to copy and to ignore the rest:
Below is some of my script just to give an example of how it's used.
pattern = "*.xlsx"
if fnmatch(name, ...
0
votes
4answers
63 views
how to match a string like hi-hello-yes using regular expression [on hold]
solution: (([^-]+-)hello|^hello)(-.+|$)
I want to use regular expression to match a sentence. The rules are:
hello must in a sentence
if - follow or ahead the hello, there must be something before ...
-1
votes
1answer
19 views
python regex sub without order
I have following string "3 0ABC, mNone\n" and I want to remove m None and \n. The catch is that 'm', \n and None can be anywhere in the string in any order. I would appreciate any help.
I can do ...
0
votes
1answer
23 views
Write Folder Contents to CSV with Regex
I am trying to use the Python script here for my own purposes. I'm no Python bloke, so hopefully someone can see what I have wrong.
The below script doesn't error out. My CSV is created with no ...
0
votes
3answers
22 views
Python regex swallows one character upon new line substituion
I am trying to understand what is wrong with my python regex.
Task:
I have the following text.
This is a red fox\LF
that chases a cat.\LF
\LF
The dog barks.
I need to correct the first sentence by ...
0
votes
1answer
18 views
QRegExp For QSortFilterProxyModel - Find All Items In A List
Am using PyQt & getting stuck on using setFilterRegExp() with a QSortFilterProxyModel. The source model outputs integers 1-30, and the QSFPM is to filter 1-30, leaving only the numbers in a ...
0
votes
1answer
29 views
python web scraping inside html commets
the following is not necessarily a question. I created a little piece of code to extract data from a web page and I want to know what do you thing about the code and how to improve it.
I need to ...
0
votes
2answers
26 views
RegEx grouping not what expected
I have the following regex that should pull out 3 groups
^(ser-num.*|\[ser-num.*])(?: )?(\w+)?(?: )?(http://.*\.com/(?:s(?:erial)?|p(?:roduct)?)/\d+(?:/)?(?:\d+|(?:\w|-)+)?)
These two strings:
...
2
votes
1answer
38 views
Python regex Find All Numbers Between 6 or 7 Digits
I am using this regex using the re module in python and getting this result:
In [156]: re.findall(r'.*\D(\d{6,7})\D.*', ' f123456 f1234567 ')
Out[156]: ['1234567']
...but I'm wanting this result:
...
-1
votes
1answer
25 views
Python writing to file errors expected string/buffer
I have a code which will replace specific text from keywords iteratively,
Problem:When i provide a file as input i get error
Coding:(works good when text is provided within code)
import re, ...
2
votes
3answers
34 views
Extract items delimited with square brackets using python regular expressions
I'm trying to split out words/phrases delimited by square brackets using a python regular expression. I want to split the output. Conditions are that section of text beginning and ending with square ...
3
votes
1answer
34 views
Why do Python findall() and finditer() return empty matches on unanchored .* searches?
The Python docs for findall() and finditer() state that:
Empty matches are included in the result unless they touch the
beginning of another match
This can be demonstrated as follows:
In ...
0
votes
1answer
44 views
python re.findall doesn't match duplicates
Let's assume the input is like this. Actually it's longer, but for the sake of clarity, I'll leave it like this.
Valid from: Wed Mar 05 15:40:45 GMT+00:00 2014 until: Thu Jan 05 08:28:29 GMT+00:00 ...
0
votes
5answers
32 views
Python: Possible to use urlparse to parse domain from cgi bin URL
I have the following input string:
/cgi-bin/ivw/CP/dbb_ug_sp;?r=http%3A//www.some-super-domain.de/forum/viewtopic.php%3Ff%3D2%26t%3D18564%26start%3D75&d=76756.76050130278
I wanted to use ...
0
votes
1answer
35 views
Perl regex meaning
I'm writing a python script using regex expressions and I found what is needed in perl, but as I am not strong in perl I don't clearly understand what is written. Here is the code:
'\\b' . $2 ...
3
votes
2answers
26 views
Python regex negative lookbehind not failing match
I'm writing a regex to match phone numbers. One of the problems I've encountered is that some postcodes look like phone numbers. For example, in Brazil, postcodes look like this:
30.160-0131
So a ...
-1
votes
2answers
35 views
Python RegEx get specific text
I'm new to RegEx. I am using python to go through a web page and pick out certain text. I have been able to pick out part of what I need with some extra character attached. In the example below I am ...
1
vote
1answer
43 views
Scrapy Python spider unable to find links using LinkExtractor or by manual Request()
I am trying to write a Scrapy spider that crawls through all the results pages on the domain:https://www.ghcjobs.apply2jobs.com.... The code should do three things:
(1) Crawl through all the ...
3
votes
3answers
61 views
How to replace all occurrences of specific words in Python
How can I achieve the following behavior in Python in the more elegant way?
Suppose that I have the following sentence:
bean likes to sell his beans
and I want to replace all occurrences of ...
0
votes
2answers
45 views
regex expression for extracting a base file name from a path
I would like to get the alphabetic parts of a file from some file paths.
files = ['data/Conversion/201406/MM_CLD_Conversion_Advertiser_96337_Daily_140606.zip',
...
1
vote
3answers
37 views
Capturing named groups in regex with re.findall
When I was trying to answer this question: regex to split %ages and values in python I noticed that I had to re-order the groups from the result of findall. For example:
data = """34% passed 23% ...
-5
votes
0answers
33 views
CPU efficient string matching for the following URLs in TCL [on hold]
I need a cpu efficient method match a random url to the following pattern. You can have https://abc.xyz.SomethingElse or https://abc.Something.xyz.SomethingElse in TCL. Would like to avoid regex if ...
0
votes
3answers
35 views
regex to split %ages and values in python
Hello I am new to python and regex.
I have a large CSV file which has a field like, %age composition that contains values such as:
'34% passed 23% failed 46% deferred'
How would you split this ...
-1
votes
0answers
45 views
how can i validate chinese characters in a string which is mixed both chinese plus english
i have checked this post here but i have hard time to understand it and use it..i would like to validate a text file which has chinese, english and numerals. i have to check whether the chinese ...
1
vote
1answer
31 views
Django URL regex “is not a valid regular expression” error
I'm having a bit of trouble configuring the following url. I want it to be able to match a pages which start off with a category and then finish with a slug, examples:
/category1/post1/
...
1
vote
2answers
22 views
Scrapy date capture with regular expression
I have a working regular expression that is parsing a date below:
(?:(September|April|June|November) +(0?[1-9]|[12]\d|30), *((?:19|20)\d\d))|(?:(January|March|May|July|August|October|December) ...
1
vote
2answers
29 views
RE match fail in python, confuse with the result on regex101
http://regex101.com/r/oU6eI5/1 , test here seam works, but when i put in Python, match whole str.
str = galley/files/tew/tewt/tweqt/
re.sub('^.+/+([^/]+/$)', "\1", str)
i want get "tweqt/"
0
votes
3answers
42 views
replace a regex match group with a dictionary value in python
I'm working on a hobby project to write a clone of a popular Amiga BBS software program. One of the functions in this program was using a short code feature, much like BBCodes on forums, to change ...
0
votes
3answers
37 views
Python regex to match “spaced out” words
When dealing with text files that have been produced using optical character recognition (OCR) I often come across lines or parts of lines
t h a t a r e s p a c e d o u t l i k e t h i s.
I ...
1
vote
1answer
56 views
Python regular expression to match a file name. Using os.walk() to get a file name
I'm using os.walk() to get files name. What I need to do is to create a list with files name that match following patterns:
if '*' will match all files.
if 'h*' will match all files beginning with ...
0
votes
2answers
32 views
How can I use re's special characters when splitting a string?
Suppose I have this variable, named string.
string = "Hello(There|World!!"
Since I want to split on multiple delimiters, I'm using re.split() to do the job. Unfortunately, this string contains ...
1
vote
1answer
42 views
Can anyone see why my python regex search is only outputtings “0”s?
I'm working on a python program to extract all the tags within a kml file.
import re
KML = open('NYC_Tri-State_Area.kml','r')
NYC_Coords = open('NYC_Coords.txt', 'w')
coords = ...
0
votes
1answer
43 views
Validate a two characters code using python
I want to verify that a string is a valid code; in particular, it should be a pair of two characters. Think of a 2-chars country code. Using the re module I came up with the following:
valid = ...
-3
votes
2answers
39 views
Find a word from text file and print part of the line using regular expression
I want to find a word from a text file and print the next word on that line using regular expression in python.
For Ex:
my name is xyz.
i like science.
i like to play volleyball.
This ...
-1
votes
5answers
27 views
Regular expression which gets the last part after a special character [on hold]
I am new to programming need some help regarding regular expressions.
I have a string like this: xxxx.yyyy.zzzzz.mystring
What I need from the above string is "mystring", so I am looking for a ...
1
vote
7answers
45 views
Regular expressions: How to filter for two things at once
I want a regular expression that will return all words in a list that contain only consonants and no special characters.
The following Python code works:
import re
words = ["xkcd", "word", "xml-"]
...
-1
votes
1answer
33 views
Split array byte string in Python
I'm trying to split a string of bytes like this:
'\xf0\x9f\x98\x84 \xf0\x9f\x98\x83 \xf0\x9f\x98\x80 \xf0\x9f\x98\x8a \xe2\x98\xba \xf0\x9f\x98\x89 \xf0\x9f\x98\x8d \xf0\x9f\x98\x98 \xf0\x9f\x98\x9a ...
0
votes
1answer
16 views
Regex throwing up sre_constants error
I am parsing the following data structure:
var teamFixtures = new WS.Panel(fixturesConfig);
teamFixtures.load([300, [[883762,1,'23-08-2014','17:00',300,'Atalanta',0,777,'Pisa',1,'2 : 0','1 : ...
1
vote
2answers
33 views
Python - regex - sorting Japanese addresses
I have to scrub a lot of Japanese addresses. This regex works on two regex test sites but I don't get the same results in my Windows terminal; I'm using Python 2.7.8 on Windows 7.
Here are the ...
6
votes
1answer
50 views
Security of regular expressions [duplicate]
Say that I want to let a user input whichever regular expression he wants, and a string to match, and I will check whether it matches using Python's re.compile. Is that secure? Is there a way for a ...
-2
votes
2answers
33 views
Match everything inside multiple instances of a tag in a string in python
Sample string:
str = "<sec>John</sec> said hi to a woman (named <sec>Mary</sec>)"
Result should be a list:
res = [John, Mary]
I should really have learned regex by now.
1
vote
2answers
1k views
python regex split string while keeping delimiter with value
I'm trying to parse a text file with name:value elements in it into lists with "name:value"... Here's a twist: The values will sometimes be multiple words or even multiple lines and the delimiters ...
13
votes
5answers
16k views
Python: use regular expression to remove the white space from all lines
^(\s+) only removes the whitespace from the first line, how to remove the front whitespace from all the lines?
11
votes
4answers
31k views
Python string match
If a string contains *SUBJECT123, how do I determine that the string has subject in it in python?
1
vote
6answers
1k views
Regex for removing whitespace
def remove_whitespaces(value):
"Remove all whitespaces"
p = re.compile(r'\s+')
return p.sub(' ', value)
The above code strips tags but doesn't remove "all" whitespaces from the value.
...