Regular Expression Using the Dot-Matches-All Mode

Normally the . doesn't match newline unless I specify the engine to do so with the (?s) flag. I tried this regexp on my editor's (UltraEdit v14.10) regexp engine using Perl style regexp mode:

(?s).*i

The search text contains multiple lines and each line contains many 'i' characters.

I expect the above regexp means: search as many characters (because with the '?s' the . now matches anything including newline) as possible (because of the greediness for *) until reaching the character 'i'.

This should mean "from the first character to the last 'i' in the last sentence" (greediness should reach the last sentence, right?).

But with UltraEdit's test, it turns out to be "from the first character to the last 'i' in the first sentence that contains an i". Is this result correct? Did I make any wrong interpretation of my reg expression?

e.g. given this text

aaa
bbb
aiaiaiaiaa  
bbbicicid

it is

aaa
bbb
aiaiaiai

matched. But I expect:

aaa
bbb
aiaiaiaiaa  
bbbicici

Answers


Your regex is correct, and so are your expectations of its performance.

This is a long-known bug in UltraEdit's regex implementation which I have written repeatedly to support about. As far as I know, it still hasn't been fixed. The problem appears to lie in the fact that UE's regex implementation is essentially line-based, and additional lines are taken into the match only if necessary. So .* will match greedily on the current line, but it will not cross a newline boundary if it doesn't have to in order to achieve a match.

There are some other subtle bugs with line endings. For example, lookbehind doesn't work across newlines, either.

Write to IDM support, or change to an editor with decent regex support. I did both.


Need Your Help

I want to implement a doubly circular linked list - runtime error in my code

c++ data-structures

Here is what i have tried. I get a runtime error :| ....to be precise, I figure there is something wrong with my push function, but i can't seem to figure it out !!

need silverlight 3 development

c# visual-studio silverlight msbuild

At work, I am on a sizable development team. Our current project is in Silverlight 3. We cannot upgrade right now due to all the regression testing (company policy)

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.