Open Serious54088 opened 1 year ago
I understand where you're coming from, but I feel that simply copying the regex from the input field is very easy and straight forward for the cases where you just want the regex?
And with regards to the errors, I think those should remain, as they are valid for that language.
Feature
Hello!
As shown in the above picture, those are my suggestions for improving the user interface of regex101.
Let me explain why I'm proposing these changes.
First, it's important to recognize this fact:
One of the most common use cases for regular expressions is in search boxes, like searching or replacing in various text editors or note-taking software.
For users in this scenario, all they need to consider in the search box is the regular expression itself. They don't need to think about creating regex objects or escaping the delimiters in literals.
For example, if you need to find a string like
"23/03"
in the Typora editor , you just need to type"\d{2}/\d{2}"
in Typora’s search box. You don't need to think about using/"\d{2}\/\d{2}"/g
ornew RegExp("\"\\d{2}/\\d{2}\"")
. (The additional escaping of/
,"
and\
in these two expressions is something to consider at the programming language level, but not for the regex itself.)Now, let's look at what issues arise when a user enters
"\d{2}/\d{2}"
in regex101's regex input field (assuming the Flavor is Javascript):/
, it warns the user that/ must be escaped
. However, using regex in Typora (or other text editors), you don't need to escape/
. Another issue is that when the user clicks the copy button on the right, it copies/"\d{2}/\d{2}"/gm
instead of the regex itself"\d{2}/\d{2}"
. Some less experienced users may directly paste/"\d{2}/\d{2}"/gm
into Typora's search box, which won't work!"
, following the logic above, both"
and\
should trigger a warning that" and \ must be escaped
, but\
does not have a warning ( In Javascript string, it is written as"\"\\d{2}/\\d{2}\"
). The logic isn't consistent. (Again, this escaping is not necessary when using regex in Typora.) Besides, the copy button on the right also has problems, as it copies"\"\d{2}/\d{2}\""gm
, which is a strange string that can not be used in source code or directly pasted into Typora's search box. For source code usage, I think it should copies"\"\\d{2}/\\d{2}\"
(string literal) ornew RegExp("\"\\d{2}/\\d{2}\"", "gm")
or/"\d{2}\/\d{2}"/gm
.Therefore, my suggestion is to remove extra escaping warnings at the programming language level. (only raise errors if the regex itself is invalid). Instead, add more copy options to cater to different scenarios.
For example, if you need to use the regex in Typora's search box, you can click the option
Copy Regex As Is
, and you will get the regex itself:"\d{2}/\d{2}"
. If you wish to create a regex object by constructor function in JavaScript code, you can click the optionCopy Regex As "" String
,then you will getnew RegExp("\"\\d{2}/\\d{2}\"", "gm")
...This will make regex101 more friendly and useful whether for programers or non-programmers. Looking forward to your reply.