title: Cannot make regular expression work in Objective-C
body: <p>For some reason I cannot make regular expressions work for multiline string. It works fine on a web</p>
  
  <p>I have a text like this:</p>
  
  <pre><code>    First Line //remove leading spaces
  Second Line //nothing to remove
    Third Line //remove leading spaces
  Fourth Line
  should be 1 line //remove leading spaces and new line next char is not a capital letter
  
   Fifth line //remove leading spaces, keep new line between the two sentences 
  </code></pre>
  
  <p>I'm trying to use this regex</p>
  
  <pre><code>^ +|\b\n\b
  </code></pre>
  
  <p>It works almost fine (except it removes more new line than needed)  in online regex editors such as <a href="http://rubular.com/r/u4Ao5oqeBi" rel="nofollow">http://rubular.com/r/u4Ao5oqeBi</a></p>
  
  <p>But it only removes the leading spaces from the first line
  This is my code:</p>
  
  <pre><code>        NSString *myText = @"    First Line (remove leading spaces\nSecond Line (nothing to remove\n  Third Line (remove leading spaces\n Fourth Line\nshould be 1 line (remove leading spaces and new line next char is not a capital letter\n\n Fifth line (remove leading spaces, keep new line between the two sentences";
          NSLog(myText);
  
          NSString *resultText = [myText stringByReplacingOccurrencesOfString: @"^ +|\\b\\n\\b"
                                                                   withString: @""
                                                                      options: NSRegularExpressionSearch
                                                                        range: NSMakeRange(0, myText.length)];
  
          NSLog(resultText);
  </code></pre>