0

When I run the following commands under ipython;

>>> s = '{\f226 Please press the} "{\f226 Input}'
>>> re.findall(r'\{\f226.*?\}',s)
['{\x0c226 Please press the}', '{\x0c226 Input}']

When I run the same command under a python script, it gives me an empty list. I use the same Python versions.

import sys, codecs, re

if __name__ == "__main__":
        f = sys.argv[1]
        tn = f + ".fixed"
        f = codecs.open(f, encoding="utf-8").read()

        brackets = re.findall(r'\{\f226.*?\}', f)
        nonbrackets = re.findall(r'\{\f226(.*?)\}', f)

        print brackets

The result is []. What should I do?

yusuf
  • 3,591
  • 8
  • 45
  • 86
  • 2
    Why don't you test with `s = r'{\f226 Please press the} "{\f226 Input}'` and `r'{\\f226.*?\}'`? The ``\`` before `f` in your text is a literal one, isn't it? – Wiktor Stribiżew May 11 '17 at 13:35
  • what is 'r'? Does it make the text unicode? – yusuf May 11 '17 at 13:36
  • 1
    I can put that in a script and have it work fine. What else is in your script? – khelwood May 11 '17 at 13:37
  • 2
    If you run this character-for-character exact code in a script, I'd expect it to crash with `SyntaxError: invalid syntax` on the first line. If you remove the `>>> ` from each line and run it, I expect it to crash with `NameError: name 're' is not defined` on the second line. If you add `import re` at the beginning, I expect it to run but produce no output, not even an empty list. Can you share the exact complete contents of the script you're running? – Kevin May 11 '17 at 13:38
  • 2
    See also [What exactly do “u” and “r” string flags do in Python, and what are raw string literals?](http://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-in-python-and-what-are-raw-string-l). In `'\f'`, `\f` is an *ASCII Formfeed (FF)*. In `r'\f'`, there are 2 chars, ``\`` and `f`. – Wiktor Stribiżew May 11 '17 at 13:38

0 Answers0