Assume infile is a variable holding the name of an input file, and similarly outfile for output file. If infile ends in .js, I'd like to replace with .min.js and ...
Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like:
And then concatenate the
If my string was:
Business -- way's
I'd like to turn this into:
ie. replace NON abc/123 into ""
I'm using Python to write a regular expression for replacing parts of the string with a XML node.
The source string looks like:
REPLACE(str1) this is to replace
REPLACE(str2) this is to replace
And the ...
Say I have a string that looks like this:
str = "The &yquick &cbrown &bfox &Yjumps over the &ulazy dog"
You'll notice a lot of locations in the string where there is an ...
I want to search key words (keys would be dynamic) and replace them in a certain format. For example:
keys = ["cat", "dog", "mouse"]
text = "Cat dog cat cloud miracle DOG ...
I need to match two cases by one reg expression and do replacement
'long.file.name.jpg' -> 'long.file.name_suff.jpg'
'long.file.name_a.jpg' -> 'long.file.name_suff.jpg'
I'm trying to do the following
re.sub('(\_a)?\.[^\.]*$' , '_suff.',"long.file.name.jpg")
But this is cut the extension '.jpg' and ...
I'm getting started with RegEx and I was wondering if anyone could help me craft a statement to convert coordinates as follows:
145.00694,-37.80421,9 145.00686,-37.80382,9 145.00595,-37.8035,16 145.00586,-37.80301,16
(Strip off the last comma and ...
related question: http://stackoverflow.com/questions/919056/python-case-insensitive-replace
What's the best way to do a case insensitive replace WITHOUT HURTING THE CACHE in the re module? I'm monitoring carefully the cache to make sure my favorite ...
I need to find, process and remove (one by one) any substrings that match a rather long regex:
# p is a compiled regex
# s is a string
I am parsing a relatively simple text, where each line describes a game unit. I have little knowledge of parsing techniques, so I used the following ad hoc solution:
I need to replace part of a string. I was looking through the Python documentation and found re.sub.
s = '<textarea id="Foo"></textarea>'
output = re.sub(r'<textarea.*>(.*)</textarea>', 'Bar', s)
I was expecting this to ...
Regards to all.
I'm developing a Image compression system using Python Image Library. The basic workflow is:
- Read all images of a certain directory with : find /opt/images -name *.jpg > /opt/rs/images.txt
- Read this ...
I want to transform a text like:
<% tex \alpha %>
For the single line replace, I did this:
re.sub(r"\$(.*)\$", r"<% tex \1 %>", text)
...and it works fine.
Now, I added ...
what is the regex for such a task? -->
replace "[[...:" with "[["
That is to say, I want to replace *some text * inside [[...: with [[.
The problem with my code ...
i got an string that might look like this
i'm currently checking for validity using, which works fine
now i'd like to replace whatever string is at the 3rd parameter.
unfortunately i cant just ...
I have some sample string. How can I replace first occurence of this string in longer string with empty sign ? Tried this but it's not working as far as I ...
i have a search expression with 1-2 groups.
i need to substitute each result with something that depends on the result value.
e.g. in the following string, replace each matched digit with it's ...
I have a string as follows:
I want to replace all the [*] section with an empty string so that I end up with a string like this:
(I'm doing this in Python ...
New to python, competent in a few languages, but can't see a 'snazzy' way of doing the following. I'm sure it's screaming out for a regex, but any solution I can ...
Using regular expressions in Python, I am trying to remove all XML-type elements in a string, except those containing QUOTE, eg
<QUOTE A="B"> should remain, but others such ...
I need some help on declaring some regex. my inputs as as such
this is a paragraph with<[1> in between</[1> and then there are cases ... where the<[99> number ranges from 1-100</[99>. ...
For python 2.5, 2.6, should I be using string.replace or re.sub for basic text replacements.
In PHP, this was explicitly stated but I can't find a similar note for python.
In a file, I have the following lines
NetConn_msa.time=0.0 etc for 60 elements.
I need to write a script to change the time from 0.0 to 0.5.
I started with
I've been yanking clumps of hair out for 30 minutes doing this one...
I have a dictionary, like so:
And a string like this:
Foo bar %foo% % ...
I would like to replace a string in form
'nnn0n' with the string in form
n is any digit. What the easiest way to do that? So, far I ...
Does anyone know how replace all
\\ in python?
But it screws it up because of the escape sequence.
does anyone know the awnser to my question?
$ pydoc re.sub :
sub(pattern, repl, string, count=0, flags=0)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
I'd like to create a regex string that would turn this text:
Hello this is a mighty fine day today
8===D 8==D 8D D 8====D 8==D 8=D 8===D
is this possible with a python ...
I need some help.
I have many rows in my text file with this :
I want to copy each row before him and change glVertex3f with glColor3f.
The result will be like ...
I'm not sure if this problem solvable with regular expressions (in Perl5 syntax), but here is self-explanatory example:
smth Y1 test X foo X Y2 bar X Y1 X X Y2
smth Y1 ...
I'm pretty new to regular expressions. I've worked out the string
(?i)\$url\[([0-9])\] to match what I'm looking for. I want a string like
"this is $url a string" to be passed ...
I want to replace parts of a string that contains the following words "$%word$%"
I want to replace it with the value of a dictionary with the corresponding key equal to word.
Suppose I have this string:
s = "blah blah blah"
Using Python regex, how can I replace each instance of "blah" with a different value (e.g. I have a list of values
I'm new to Python and I am trying to replace all uppercase-letters within a word to underscores, for example:
Any ideas/tips/links/tutorials on how to achieve this?
I want to remove all commas from a string using regular expressions, I want letters, periods and numbers to remain just commas
I have a string like this one:
| option1 = foo
| option2 = foo
| <!-- more options -->
| something = xxx
| thisoption = xxx
| <!-- more options -->
I want it to be ...
I'm trying to change a string that contains substrings such as
At the line break is CRLF
The words before and after the code change. I only want to replace ...
I'm trying to rewrite the equivalent of the python replace() function without using regexp. Using this code, i've managed to get it to work with single chars, but not with more ...
Hey I'm trying to figure out a regular expression to do the following.
Here is my string
I need to split this string by the comma's. Though due to the comma's used ...
Thanks all for your help. I must say that it makes sense to just use the built-in split-to-list feature of strings and check each element. It seems pretty safe. However, it takes a long time to process a large dataset and check each value to see if it is a period, in this case the census numbers for the state of ...