1

Or Should I change my question to 'how to implement regular expression tester like these': regular expression editor python

Maybe this is more like a programming question. My application will read in an article and expose a variable, say TEXT, to represent this article. Allow users to write Python re compatible script to manipulate the TEXT (the article), particularly to replace something.

For example, users could write the following commands, and my app should read it in and execute it:

p = re.compile( 'red')
p.sub( 'color', TEXT)

And I will release my app with something like py2exe, so I think How can I make one python file run another? doesn't work.

I know how to write regular expression, but now "using a Python script to run a Python script" really confuses me.

Community
  • 1
  • 1
minion
  • 561
  • 4
  • 17
  • 1
    I don't understand what are you asking. You want to let the user provide a regular expression and possibly some replacement text and apply this to a file? But if this is the case I don't see the problem. Obtain the text from the user and then do `re.compile(the_text)` to obtain a regex and use the `sub` method. – Bakuriu Jan 30 '16 at 08:30
  • 2
    this should answer your question http://stackoverflow.com/questions/7974849/how-can-i-make-one-python-file-run-another – ifedapo olarewaju Jan 30 '16 at 08:39

1 Answers1

0

Do you want to write second word? You need to use input():

word = input('Specify color\n')

U can use just string.replace():

text = 'red'
text.replace('color', word)

If you want to use RegExp:

import re
re.sub('color', word, text)
JRazor
  • 2,707
  • 18
  • 27