-
-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
log-parser improvements #1162
Comments
What would be an ideal Regex solution to this ? Maybe something like : def tag_with_user_name(line) do
case Regex.run(~r/User\s+(\S+)/, line) do
[_, name] ->
orphans_regex = ~r/(?<!User\s)(#{name})/
# May use #{name} instead of the capture group
bold_orphans = String.replace(line, orphans_regex, "**\\1**")
"[USER] #{name} #{bold_orphans}"
_ ->
line
end
end Such a solution uses a negative lookbehind which (I think) has to be of fixed length ( Did I miss some elegant Regex way to achieve this ? Alternative ideaAs an alternative, what about a function hilighting (it can be by bolding) some important words during parse ? Since the important words could be changed by configuration, it is passed to the function as an argument (list of strings ?). It would probably be solved by something like this: @spec highlight_important(String.t(), Enum.t()) :: String.t()
def highlight_important(line, important_words)
def highlight_important(line, []), do: line
def highlight_important(line, important_words) do
important_regex = ~r/\b(#{Enum.join(important_words, "|")})\b/
String.replace(line, important_regex, "**\\1**")
end |
There are some improvements to this exercise proposed in the initial PR that got postponed so we can see how the exercise is doing first and maybe collect more improvement ideas first.
Exercise doesn't teach that different delimiters can be used for regular expressions
Maybe add a step that involves parsing several
/
and ask them to use another delimiter for readability. Can be checked via the analyzer because the delimiter is kept in the AST.Exercise doesn't teach about compiling regex with variable content
I wanted to add some step that would require an interpolated regex with escaping a variable, but I couldn't come up with anything thematic that wouldn't be better done with
String.starts_with?
.How about adding a step to
tag_with_user_name/1?
Maybe something like bolding the user names whenever they are mentioned without "User"?
The text was updated successfully, but these errors were encountered: