in reply to Match a string that can contain a carriage return in a random position.

Hi,

according to my Camel (3rd edition), on page 150, you can use a /s modifier to allow '.' to also match newlines..

So try something like this?
/cn=(.+),ou=(.+),ou=(.+),c=(.+)/s

C.

  • Comment on Re: Match a string that can contain a carriage return in a random position.
  • Download Code

Replies are listed 'Best First'.
Re: Re: Match a string that can contain a carriage return in a random position.
by CountZero (Bishop) on Dec 23, 2002 at 14:11 UTC

    Not a bad suggestion, BUT:

    1. As the file to be read in is so large, it will have to be dealt with line by line.
    2. The lines will break at the 80th position.
    3. Using the /s-switch in the regex will solve nothing as you will only find the newline-character at the end of the line just read in.

    I would suggest rather to first normalize the file, i.e. remove the newlines at the 80th positions and concatenating the various parts of each DN together so as to have one line per DN.

    Then you can use the regex /cn=(.+),ou=(.+),ou=(.+),c=(.+)/

    Finally you de-normalize the DN's again by adding -if necessary- newlines at position 80 so as no to break the other tools.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Re: Match a string that can contain a carriage return in a random position.
by FamousLongAgo (Friar) on Dec 23, 2002 at 13:46 UTC
    In that case the regex would have look like this:
    /c\n?n\n?=\n?([^,]*)\n?,\n?…
    etc, etc. One suggestion is to take the basic regex above and auto-generate the necessary one by interpolating optional newlines after each character, but I think the poster is looking for a neater hack. I wish I could think of one!