We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Faibbus • 1 year ago

(?i) for case-insensitive pattern would improve many examples.

unaimillan • 1 year ago

Faibbus Could i use this for single group? Something like that: (?<name>[\w-[A-Z]]+)\.(?i)(?<extension>jpe?g|png|bmp)

Marchete • 1 year ago

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.

James Markey • 1 year ago

Very good exercise, thank you!

clonex10100 • 1 year ago

Do python regular expressions work the same way

RunninglVlan • 1 year ago

You're saying that metacharacters ^ and $ match start and end of string, but they actually match start and end of lines.

KarlFaktor • 1 year ago

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.

Marchete • 1 year ago

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])

Tiramon • 1 year ago

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

Aschente • 1 year ago

Why does the expression @"<[a-zA-Z=\s""-_:]+?>" also match tags starting with a question sign?

Tiramon • 1 year ago

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

Tiramon • 1 year ago

found it ... the '-' also needs to be escaped ...

Maxlaxs • 1 year ago

remember a-zA-Z0-9
and /? in the start after <