I have a function that makes a regexp for each elemnt of given array, returning array of matched elements.

The function gets array from two soures:

1. listing of a file directory (i.e. file names are in the array);

2. list of a file contents (array holds text strings of almost same file names).

OK. My problem is: the regexp matches only for case 1. and never for case 2. For example, regexp set to look for a word "mass" - array elements that came from case 2. will not match - though there is an element that holds the word, while array coming from case 1. will match. - Though all is the same - regarding the function w/ regexp - it gets array and return array.

So I conclude that the problem is in sources - file contents seems "clearer" for the regexp than dir. contents. So, I conclude some mysterious art is needed to process some invisible characters that print ">$array$i<" does not show but regexp detects.

PS File names are from Linux EXT4 FS w/ UTF-8 encoding, if relevant.

Please, Your advice.


In reply to RegExp and hidden (not printable) characters. by humble

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.