View Single Post
Old 10-03-2010, 05:46 AM   #76
Manichean
Wizard
Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Manichean's Avatar
 
Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
Quote:
Originally Posted by da_jane View Post
If I want to remove multiple lines of text, do I enclose my reg expressions in parentheses and then separate the sets by a ?
If I understand you correctly, you want to do something like
Code:
(set1)?(set2)
That would match the strings "set1set2" and "set1set1set2", as the question mark is interpreted as a quantifier to be applied to the first group. There are two ways you can match multiple lines, both depend on you knowing where the linebreaks are (or could be).
The first way ist to use whitespaces: "\s*?" will match a linebreak, as, on windows, it is displayed as two whitespaces (carriage return and linefeed). Put that in the place(s) you expect a linebreak to happen- it will let the whole expression match even if there isn't any linebreak, that's why I used the "*" quantifier.
The second way would be using the dot and the dotall- flag, as in you'd put ".*?" where you expect linebreaks to happen, and append or prepend your whole expression with the flag construct, "(?s)". The same remarks as in the first way apply, plus a caveat: be careful when using this, as the dot doesn't only match whitespaces, but any characters. You might accidentally match more than you intended to.

For the record, I think you got confused at the point where I was talking about flags, right? If you have suggestions how to improve the tutorial so that doesn't happen, I'd be glad to hear them.
Manichean is offline