in reply to Re: Regexp to match regardless of whitespace
in thread Regexp to match regardless of whitespace

good idea, I may be able to make that work.

The issue is that my file is several MB and the VAST majority of lines will not match - so I'd like to check for a match before wasting the processing time to remove whitespace.

Also I need to remember the original string (with spaces) as I need to put it back as it was (after changing a couple things)

  • Comment on Re^2: Regexp to match regardless of whitespace

Replies are listed 'Best First'.
Re^3: Regexp to match regardless of whitespace
by locked_user sundialsvc4 (Abbot) on May 03, 2012 at 17:22 UTC

    With regard to the first paragraph, I would say that “this consideration is of non consequence,” because the computer can perform the operation in a few nanoseconds using a single regex.

    With regard to the second one, however, there could be a bit more of a problem, because when you do go about designing the code to “change a couple things,” you will perhaps need to be extremely careful to design the algorithm to always change the right things and to do so consistently in all cases.

    Nevertheless, each of these concerns are basically independent of one another, and therefore I would proceed in this course.   Removing the white space will allow you to use a regex efficiently to winnow out the lines-of-interest wheat among millions-of-lines of chaff, and that alone is enough.