I have a list of strings - something like
mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text']
I want to find the first occurrence of anything that starts with foobar. If I was grepping then I would do search for foobar*. My current solution looks like this
for...
Source text: United States Declaration of Independence
How can one split the above source text into a number of sub-strings, containing an 'n' number of words?
I use split(' ') to extract each word, however I do not know how to do this with multiple words in one operation.
I could run through the list of words that I have, and create...
Is there any tool or utility or perl/python script that can find longest repeated substrings in a large text file and print those patterns and the number of times each pattern occurs?
...
Situation:
I am writing a basic templating system in Python/mod_python that reads in a main HTML template and replaces instances of ":value:" throughout the document with additional HTML or db results and then returns it as a view to the user.
I am not trying to replace all instances of 1 substring. Values can vary. There is a finite...
Using PHP I'd like to compare an actual ip address to part of one, and see if it matches.
For example I want to see if the address matches 12.34..
<?php
$rem_address = getenv('REMOTE_ADDR');
$temp = substr ($rem_address,0,6)
if ($temp == "12.34.") echo "It's a match";
?>
Is there an easier/better way to do this?
...
How to replace a set of characters inside another string in Python?
Here is what I'm trying to do: let's say I have a string 'abcdefghijkl' and want to replace the 2-d from the end symbol (k) with A. I'm getting an error:
>>> aa = 'abcdefghijkl'
>>> print aa[-2]
k
>>> aa[-2]='A'
Traceback (most recent call last):
File "<pyshell#2>",...
How do you the following: given a string, generate all the possible ways to parse that string into substrings (time is important, space dont' care).
For example, given the string ABCD, I need to generate:
ABCD
A BCD
A BC D
A B CD
AB CD
AB C D
ABC D
A B C D
Probably a recursive solution, but I can't quite get it to work.
...
suppose to have the following string:
commandone{alpha} commandtwo{beta} {gamma}commandthree commandtwo{delta}
and I want to abtain:
commandone{alpha} beta {gamma}commandthree delta
well I'm triying with regex and sed, I can easily find if is it present the pattern I look for
/commandtwo{.*}/ but not erasing commandtwo and the foll...
Hi
Can somebody tell me how to highlight common substrings between two buffers in Emacs?
I can write a script to do that but was wondering if there was a built-in macro in Emacs by which I can do this.
Thanks,
Raj
...