Search code examples
regexxcodewhitespacecombinationsend-of-line

Regex in xCode: any number of any whitespace characters including "end of line"?


I my case I have the following text:

- (NSUInteger) launcherView:(HMLauncherView *)launcherView 
        numberOfIconsInPage:(NSUInteger)page;

And I want to find all the matches for this method. The regexp should look like something like this:

launcherView:<any number of characters><any number of whitespaces or "ends of line">numberOfIconsInPage:

I know <any number of characters> means (.+) and <whitespace> means \s but how to write the whole expression? My main problem - I can't make it searching for any combination of whitespaces because it differs whitespace characters and "end of line".


Solution

  • The Regex could be this one:

    /launcherView:.+(\s*|\s*$)numberOfIconsInPage:/
    

    In particular, the ".+" matches any character, the (\s*|\s*$) matches either only whitespaces until the "numberOfIconsInPage" or any number of whitespaces until the end of line.