Tagged Questions
3
votes
2answers
51 views
Is there a more sensible way of writing this regular expression?
The following regular expression is written in the Python dialect:
^( )*#(\s+\S(.*\S)?)?$
Can anyone see a better way to wright this? For those not sure what it is saying:
It matches an entire ...
0
votes
1answer
25 views
Why local variable gets “remembered” in this case?
def word_to_syllable(w,li=[]):
if not w:
return li
pattern = """
########
"""
pattern = re.sub("C","[^aeiou]",pattern)
pattern = re.sub("V","[aeiou]",pattern)
match ...
0
votes
1answer
23 views
Spelling corrector for non-English characters
Having read Peter Norvig's How to write a spelling corrector I tried to make the code work for Persian. I rewrote the code like this:
import re, collections
def normalizer(word):
word = ...
0
votes
1answer
36 views
Python Regular Expression Escape or not
I need to write a regular expression to get all the characters in the list below..
(remove all the characters not in the list)
allow_characters = ...
3
votes
2answers
40 views
Python regex - get all values from CSS declaration
I am working on a simple CSS parser in Python. Right now I want to extact all values from this string: "1px solid rgb(255, 255, 255)". Right now my pattern (which is not working) is: "\S+[^rgb]+". ...
0
votes
3answers
40 views
String greater-than-less-than Tests Against a Regular Expression
I am looking for matches between an alphabetically sorted list of strings and a regular expression using python.
The regular expression is relatively simple, something like "block_number_[0-9]+", ...
0
votes
1answer
27 views
regex pattern to match specific start and end anchors with variable words in between
I am trying to normalize unstructured text files. I can't seem to figure out the expression for matching specific start and end boundaries with any degree of success.
sample texts:
"Section 13 - ...
1
vote
2answers
46 views
Remove nested newline characters in delimited file?
I have a caret-delimited file. The only carets in the file are delimiters -- there are none in text. Several of the fields are free text fields and contain embedded newline characters. This makes ...
4
votes
3answers
51 views
regex - how to match group of unique characters of certain length
I'm looking for a regex that will match ad-hoc groups of characters of certain length only if all its characters are unique.
For the given string example:
...
-2
votes
1answer
31 views
Regex: Match repeating exact string of previous matched patten
I want to match parts of the string that is certain characters long (generic case: it will be a random patten) and will be matched again in the coming part of the entire string.
For the given string ...
1
vote
3answers
30 views
returning string matching regular expression
I have a textfile with lines of which I want to extract one line that matches a certain pattern. Can I search for that line with a regular expression and return it, to work with it afterwards? Is ...
1
vote
2answers
39 views
regex named group starting with but not ends with
I have two regexes (simplified to be equal)
r'^(?P<slug>(^foo)[-\w]+)/$'
r'^(?P<slug>(^foo)[-\w]+)/$'
I would to add an exclusion on the first to check for the end so the latter wins.
...
1
vote
3answers
46 views
Regex replace before and after text, keep text in place
I have some text like
<br />
blah
<br />
blah blah
Which im trying to change to:
<p>
blah
</p>
<p>
blah blah
</p>
I have the following regex
newContent = ...
0
votes
2answers
46 views
Python: Use list.index with regular expression
I have lists of strings of which i want to extract a certain value:
["bla","blabla","blablabla","time taken to build model: 5.1 seconds", "blabla"]
Normally I would look for the index of the ...
1
vote
3answers
45 views
Python regex - (\w+) results different output when used with complex expression
I have doubt on python regex operation. Here you go my sample test.
>>>re.match(r'(\w+)','a-b') gives an output
>>> <_sre.SRE_Match object at 0x7f51c0033210>
...