We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
(?i) for case-insensitive pattern would improve many examples.
Faibbus Could i use this for single group? Something like that: (?<name>[\w-[A-Z]]+)\.(?i)(?<extension>jpe?g|png|bmp)
Well, (?i) simplifies the regex in most cases, and yes, maybe the proposed solution isn't the shortest:The pattern on "Exercise 5 - Search Image Files" can be simplified to Pattern_Exercise5=@"(?i)[\w\.+_\-=\(\)]+\.(jpe?g|gif|png|bmp)";
And "Exercise 6 - Image Files with Path" to: public static string DrivePattern =@"(?<drive>\b[a-z])"; public static string DirPattern =@"[a-z0-9\-+_=\(\)]+"; public static string DirsPattern =@"(?<path>(?:" + DirPattern + @"\\)*)"; public static string TextPattern = @"[a-z0-9\.\-+_=\(\)]+"; public static string FilePattern = @"(?<name>" + TextPattern + @"\.(?:jpe?g|png|bmp|gif)\b)"; public static string Pattern_Exercise6 = "(?i)"+DrivePattern+@":\\"+DirsPattern+FilePattern;
The thing is that in many languages is easier to declare case-insensitive matches in other ways (Like RegexOptions.IgnoreCase in C#, /i in bash, etc). For me it's clearer to use a parameter option than the (?i) operator.
Very good exercise, thank you!
Do python regular expressions work the same way
You're saying that metacharacters ^ and $ match start and end of string, but they actually match start and end of lines.
The task description is unclear for some exercises and a correct solution can only be achieved by inspecting the reference matches. E.g., the task description of Exercise 5 states that valid extensions for images are jpg,jpeg,png,bmp,gif (all lowercase). The reference matches indicate that also uppercase letters are allowed.
Because the last description line is important:"//The filesystem is case insensitive, so name and extension can be on any case."
Both "filename" and "extension" are case insensitive. I can't write jpg,Jpg,jPg,JPg, etc.. with all possible combinations of lower and uppercase, it's not practical. So the exercise just declares the filesystem as case insensitive (like NTFS or FAT32 real filesystems])
exercise 3 works also without character set substraction ...vowels in the first position are not tested by the validators but the exercise says only consonants in 1st position
Why does the expression @"<[a-zA-Z=\s""-_:]+?>" also match tags starting with a question sign?
yes this is very strange i had to add a [^?] to not match those tags ... no idea why it thinks that it should match it
found it ... the '-' also needs to be escaped ...
The '-' is tricky inside character sets :)if you use it in the middle of any other two normal characters it means a range, so the expression @"<[a-zA-Z=\s""-_:]+?>" considers all '-' as range metacharacter. Your expression is:a-z --> A range from 'a' to 'z'A-Z --> A range from 'A' to 'Z'= --> The equal character\s --> Space"-_ --> A range from '"double quote" to "underscore": --> Colon character
You need to either escape it or place it last.
remember a-zA-Z0-9and /? in the start after <