Note that there are some explanatory texts on larger screens.

plurals
  1. POpython regex: pattern not found
    primarykey
    data
    text
    <p>I have a pattern compiled as </p> <pre><code>pattern_strings = ['\xc2d', '\xa0', '\xe7', '\xc3\ufffdd', '\xc2\xa0', '\xc3\xa7', '\xa0\xa0', '\xc2', '\xe9'] join_pattern = '|'.join(pattern_strings) pattern = re.compile(join_pattern) </code></pre> <p>and then I find pattern in file as </p> <pre><code>def find_pattern(path): with open(path, 'r') as f: for line in f: print line found = pattern.search(line) if found: print dir(found) logging.info('found - ' + found) </code></pre> <p>and my input as <code>path</code> file is </p> <pre><code>\xc2d d\xa0 \xe7 \xc3\ufffdd \xc3\ufffdd \xc2\xa0 \xc3\xa7 \xa0\xa0 '619d813\xa03697' </code></pre> <p>When I run this program, nothing happens.</p> <p>I it not able to catch these patterns, what is am I doing wrong here?</p> <p><strong>Desired output</strong> - each line because each line has one or the other matching pattern</p> <p><strong>Update</strong></p> <p>After changing the regex to </p> <pre><code>pattern_strings = ['\\xc2d', '\\xa0', '\\xe7', '\\xc3\\ufffdd', '\\xc2\\xa0', '\\xc3\\xa7', '\\xa0\\xa0', '\\xc2', '\\xe9'] </code></pre> <p>It is still the same, no output</p> <p><strong>UPDATE</strong></p> <p>after making regex to </p> <pre><code>pattern_strings = ['\\xc2d', '\\xa0', '\\xe7', '\\xc3\\ufffdd', '\\xc2\\xa0', '\\xc3\\xa7', '\\xa0\\xa0', '\\xc2', '\\xe9'] join_pattern = '[' + '|'.join(pattern_strings) + ']' pattern = re.compile(join_pattern) </code></pre> <p>Things started to work, but partially, the patterns still not caught are for line </p> <pre><code>\xc2\xa0 \xc3\xa7 \xa0\xa0 </code></pre> <p>for which my pattern string is <code>['\\xc2\\xa0', '\\xc3\\xa7', '\\xa0\\xa0']</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload