Regular expression for matching \n and space

I am trying to use regular expression within my perl script to parse a file to match:

Space and "\n" (newline) in a alternating manner - i.e first i would like it to match space then a "\n", then a space (which is on a new line in the file... and so on)

thanks, -AD

Answers


Try this:

(^ \n)+

You can do:

if($file =~/ |(?: \n)+ ?/) {
        print $file." has the pattern\n";
}

The regex used is |(?: \n)+ ? which matches:

  • Single space or
  • One or more space\n followed by an optional space

Need Your Help

Is there a way to roll-back the Android Plug-in on Netbeans?

android plugins netbeans rollback

I went ahead and installed the latest Android Plug-in for Netbeans not realizing that it required the new Sdk. I am unable to get the newest SDK and now my project won't compile.

Create a standalone view in storyboard to use programatically

objective-c ios xcode uistoryboard

I'm trying to create and design a UIView using a storyboard but include it in a UIActionSheet programatically. This is basically to avoid using CoreGraphics positioning functions with pixels

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.