We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Strange behavior with regex lookarounds

I'm having a real strange behavior using regex lookarounds for Lexems inside the EditControl.

I defined my Lexem as follows:


new Lexem() { StartText = "hell(?=o)", IsRegex = true, LexemType = EditTokenType.Keyword, FormatName = "KeywordFormat" }


For testing purpose this is the only Lexem in my CustomLanguage class which inherits from ProceduralLanguageBase.
In the EditControl the Lexem matches "hellO", but not "hello". CaseSensitive is set to false in my CustomLanguage class.
When i change my regex to "hell(?=O)" it matches "hello" but not "hellO".

Apart from that, the correct match would be "hell" in both cases.

How can i fix this?

My CustomLanguage class:

public class CustomLanguage : ProceduralLanguageBase
    {
        private List<EditFormats> formats = new List<EditFormats>()
        {
            new EditFormats() { Foreground = Brushes.Red, FormatName = "KeywordFormat" }
        };

        private List<Lexem> lexems = new List<Lexem>()
        {
            new Lexem() { StartText = "hell(?=o)", IsRegex = true, LexemType = EditTokenType.Keyword, FormatName = "KeywordFormat" }
        };

        public CustomLanguage(EditControl control)
            : base(control)
        {
            Name = "Custom";
            FileExtension = "cus";
            ApplyColoring = true;
            SupportsIntellisense = false;
            SupportsOutlining = true;
            CaseSensitive = false;
            TextForeground = Brushes.Black;
            Lexem = new LexemCollection(lexems);
            Formats = new FormatsCollection(formats);
        }
    }

MainWindow code-behind (setting the DocumentLanguage):

public MainWindow()
        {
            InitializeComponent();
            var customLanguage = new CustomLanguage(editControl1);
            editControl1.DocumentLanguage = Syncfusion.Windows.Edit.Languages.Custom;
            editControl1.CustomLanguage = customLanguage;
        }


I'm using .Net 4.6 and Syncfusion 14.4.0.15

Attachment: EditControlSample_c94ee2e5.7z

5 Replies

KR Kannan R Syncfusion Team January 27, 2017 06:31 AM UTC

Hi David,   
  
Thank you for contacting Syncfusion support.    
  
Query 1: How to provide Case insensitive Regex Match?   
   
We must use Inline Case Insensitive option to achieve this reported behavior. Please make use of below MSDN link and code snippet to achieve this requirement.    
  
  
Code Snippet: [C#]   
   
   
new Lexem() { StartText = "hell(?i)(o)", IsRegex = true, LexemType =EditTokenType.Keyword, FormatName = "KeywordFormat" },   
   
   
Screenshot   
   
    
   
Query 2: Usage of default Case Insensitive option in Custom Language.   
   
In this Case, Sensitive option in Custom Language is to enable / disable Case sensitivity for all other items like Keyword and remaining options but not for Regex Input. 
  
For Example   
   
Here, we have added public as Keyword and set as case insensitive. So, it will enable user to highlight any public, even if user enter it as different mixed cases but not for the Regex option. Please refer with the below example.    
  
Screenshot   
   
    
   
We have also modified your sample; it helps to achieve this requirement and it can be downloaded from below location.    
  
   
Query 3: Word hell must match all the three cases.    
   
No, as we have provided an option after word “hell”, Regex would not match to it and expect the next character “o” input in it.  
 
Kindly check with the above solution and let us know if it is helpful.   
  
Regards   
Kannan   
 



DW David Wimmer January 27, 2017 09:40 AM UTC

Hi Kannan,

Query 1: I don't want to match case insensitive.

Your regex hell(?i)(o) has a different meaning than hell(?=o).

Your regex means you want to match hello or hellO, but I want to match hell when it is followed by an o. So it only matches hell in hello, but not hellO.
But when I'm using the regex hell(?=o) as StartText in Lexem it matches whole word hellO and not hello, though it should match hell when it is followed by an o.

See http://regexr.com/3f5nl to text the regex or test it with System.Text.RegularExpressions.Regex from the .Net Framework

Query 2: Is clear to me.

Query 3: Explained in query 1.

Kind Regards
David



VR Vijayalakshmi Roopkumar Syncfusion Team January 31, 2017 06:23 AM UTC

 Hi David,

From your update, we come to know that your reported issue with EditControl as follows:

Using the regex you have provided "hell(?=o)" , the word hello matches with the Lower case "o" , whereas the word matches with Upper case "O" at our end.

We have also taken the video for the same:

Video: https://www.syncfusion.com/downloads/support/forum/128517/ze/Editcontrol_video1708501745 

Please go through the video and confirm us whether you have reporting this issue. Also let us know that you want to match the word hell with "o" irrespective of Case Sensitive?

If not please brief about the issue , so that it would be helpful for us to proceed further on this.

Regards,
Vijayalakshmi V.R. 



DW David Wimmer February 1, 2017 08:20 AM UTC

Hi Vijayalakshm,

yes, I'm reporting the issue as shown in the video.
And I want to match the word hell with "o" considering Case Sensitive.

Examples of the EditControl-behavior I expected using the regex "hell(?=o)":

Input
IsMatch
Formatted text
hello
Yes
hello
hellO
No
hellO
hell
No
hell
Hello
No
Hello
Chello
Yes
Chello

Hope this helps!

Regards,
David


VR Vijayalakshmi Roopkumar Syncfusion Team February 6, 2017 06:43 AM UTC

Hi David,

We have confirmed the reported issue with EditControl is a defect and have logged a defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates.

https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents 

Regards,
Vijayalakshmi V.R. 


Loader.
Live Chat Icon For mobile
Up arrow icon