1
vote
0answers
9 views

Re-ordering groups in regex findalls

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% ...
-2
votes
0answers
10 views

CPU efficient string matching for the following URLs in TCL

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 ...
-1
votes
3answers
28 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
41 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
28 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
18 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
24 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
38 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
35 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
50 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
31 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
41 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
41 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
35 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
43 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
29 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
49 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
27 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.
-2
votes
1answer
29 views

python regex to match lines not with quotes

I have a regex which is used to match the text, but i need to match the text leaving the text within quotes. Consider: I have a pen1 I have a pen1 "green" In fact i need to leave the text within ...
-1
votes
4answers
47 views

Parse a string from a string with regex

I need a regex that will parse a string from a string. To show you what I mean, imagine that the following is the content of the string to parse: "a string" ... \\"another \"string\"\\" ... "yet ...
2
votes
2answers
64 views

What Regex to use in this example

I am parsing a string that I know will definitely only contain the following distinct phrases that I want to parse: 'Man of the Match' 'Goal' 'Assist' 'Yellow Card' 'Red Card' The string that I am ...
1
vote
2answers
37 views

Find all delimiters next to substring in string and replace in python

Sample string: s = "<sec>John</sec> said hi to a woman (named <sec>Mary)</sec>" I need to transform this to: s = "<sec>John</sec> said hi to a woman (named ...
-1
votes
1answer
72 views

How to split a string into a list but not brackets?

Sorry about the title - I wasn't sure how to word it. Anyway, I'm writing a markup language compiler in python that compiles into HTML. Example: -(a){href:"http://www.google.com"}["Click me!"] ...
-1
votes
2answers
25 views

regex expression not recognising the other lines

I have a regex which I would like to match a couple of things: Here is a link to the examples and the code which I have started but for errors which I cannot determine in my regex is not recognising ...
0
votes
1answer
24 views

Convert re.match/re.search to string

I've been looking through having re.match/re.search find a certain int from my file. The int will differ, which is why I'm using regex in the first place. Here is the file: Money: *1,000 coins *2 ...
2
votes
3answers
42 views

grouping using regex ending with colon ':'

I have a code which is used to group the words inside the paranthesis,if it has got a same name before paranthesis. Eg: car __name__(skoda,audi) car __name__(benz) Outputs: car ...
0
votes
1answer
33 views

Name error with regular expression

I am trying to parse the a file content with regular expression as in the code below. If I print the system name inside 'IF' suite, it works. But If I try to do anywhere outside, its throwing name ...
1
vote
3answers
50 views

Python regex to add a character to all words in a string except and

I want to be able to generate 'foos, bars and bees' from 'foo, bar and bee' using re.sub. I can't even get just adding 's' to all words to work. I'll work on excluding 'and' once I get that part. ...
1
vote
2answers
40 views

match pattern to its counterpart from a list of patterns

In Python, I want to have a pair like this: patterns: abc, def ghi, jkl mno, xyz The idea is: given a string, I want to search for occurrence of any of the pattern p from patterns and when I find ...
-4
votes
1answer
49 views

Get two numbers in regex

I have the following string: s='123223423424,1982379879343' I need to get both numbers (without using a split()). Here is what I have so far: re.match(r'\d{7,20}',s).group() However, this only ...
0
votes
5answers
41 views

How to replace a text using the found expression with regex?

I have a .txt file that contains the following lines (hundreds like that) : AAIT AC Asia Information Tech MSCI Ishares AAL American Airlines Group Inc. AAME Atlantic American Corp AAOI ...
-2
votes
1answer
37 views

Python Regex to match time format works - why?

I'm writing a function that needs to match hour/minute/seconds in order to allow the user to provide a time argument on the command line in a more convenient fashion than just specifying the number of ...
2
votes
3answers
69 views

Correcting repeated letters in user messages

I try to analyze messages from social media or chats. A common issue is this special kind of misspelling where people use repeated characters to express their emotions or whatever e.g. "wowwwwww!" ...
0
votes
2answers
39 views

python regex search findall capturing groups

I just want to get "66664324", the content between ")" and "-". Why did the search method get the ")" and "-" themselves. a="(021)66664324-01" b1=re.findall('\)(.*)-',a) >['66664324'] ...
0
votes
1answer
12 views

Django url pattern order and regex

There is something I can't understand which is happening with my app. This is what django documentation says. Django runs through each URL pattern, in order, and stops at the first one that ...
0
votes
1answer
29 views

Python regular expression to print out sections of a string

Here is my code (apologies for the lengthiness of testString, I was not too sure how to format it): testString = ...
0
votes
0answers
39 views

When to use regex and when to use full text search, and why

Background: I am still new to Python. What I have been learning when it comes to string searching has always centered around regex. Use Case: An immense amount of text documents that need to be ...
1
vote
1answer
23 views

select a list of interfaces with Python CISCOCONFPARSE and regex

I use a double loop to select all interfaces GigabitEthernet1/0/1 to 1/0/16 and 2/0/1 to 2/0/16 using efficient tool CISCOCONFPARSE : here is the example, that works : CONFIG_PARSED = ...
0
votes
1answer
20 views

Use of re.compile and groups in a regular expression in python

The input file, named consensus, is of the following form: r Tor4ever AAcif1htILdru0BO0qX7OwGVhAU oHlbWBdaN3+QSleqBVL9/yAdcRs 2014-07-31 21:42:43 s Exit Fast Guard HSDir Running V2Dir Valid v Tor ...
2
votes
1answer
49 views

Renaming Variables And Method Names In A Python Source File

I'm trying to write a Python program that will basically take as input a raw Python source file and change all variable names to V, and all method or function names to F and leave everything else as ...
-1
votes
2answers
42 views

Delete regex matching part of file

I have a file ,and i need to delete the regex matching part and write remaining lines to a file. Regex matching Code to delete file: import re with open("in1.txt") as f: lines = f.read() m = ...
0
votes
3answers
32 views

Find a paragraph and find a string inside this paragraph with REGEX

I have inside an HTML page some lines like this : <div> <p class="match"> this sentence should match </p> some text <a class="a"> some text </a> ...
0
votes
5answers
51 views

parse using regex and print the line

I have a regex which is used to print the lines of file within a specified range. Eg: my _car_(10) skoda audi my home good my _car_(11) benz outputs as: (10) skoda audi (11) benz EXPECTED:(I ...
0
votes
2answers
46 views

how to match `“` with regex in python?

There is a symbol in tweets : “ “@BrownieSWP: High is s***????” you like 12 tf The symbol is not ". I write this regex to match it: re.sub('(“|”)', '"', tweet) This regex (“|”) worked in ...
1
vote
5answers
51 views

Parse CSV file with commas inside fields

I just received a file from a colleague and don't know how to parse this: Input: key,value1,"value2,hello" Desired output: key,value2 Perl or Python are the languages I understand. Thanks, ...
-1
votes
2answers
21 views

Python regex group() works explanation

Could someone please explain why below each print gives different result? thanks. import re s = "-h5ello" m = re.match("-\w(\d\w+)", s) print ' m.group(): ',(m.group()) print ' m.group(0): ...
2
votes
2answers
26 views

re.split - Leave matched string in place?

If this is drop-dead simple or a duplicate, please let me know. I couldn't find an answer for this here already. Python's re.split will hack up a string and return a list of strings split by the ...