I would like to see a julia code snippet that will read the file and return strings (string type) that match the regular expression.
I welcome a few methods, but the output should be equivalent to the following:
$> grep -E ^AB[AJ].*TO' 'webster-unabridged-dictionary-1913.txt' ABACTOR ABATOR ABATTOIR ABJURATORY
I use GNU grep 3.1 here, and the first line of each entry in the file is all the words caps.
My favorable solution uses a simple loop and is very easy to understand.
julia> open("webster-unabridged-dictionary-1913.txt") do f for i in eachline(f) if ismatch(r"^AB[AJ].*TO", i) println(i) end end end ABACTOR ABATOR ABATTOIR ABJURATORY
x -> f(x)
open()
try-finally-close
r"<regex_literal_here>"
julia> reg = r"^AB[AJ].*TO"; julia> typeof(reg) Regex julia> test = match(reg, "ABJURATORY") RegexMatch("ABJURATO") julia> typeof(test) RegexMatch
filter, .
filter
filter(line -> ismatch(r"^AB[AJ].*TO",line),readlines(open("webster-unabridged-dictionary-1913.txt")))
filter , Boolean , , true. line -> ismatch(r"^AB[AJ].*TO",line)", , ( ) line.
true
line -> ismatch(r"^AB[AJ].*TO",line)"
line
, , , , for, eachline. , , , , , .
eachline
Just placing ;in front is a way to use Julia command line commands, so this works in Julia REPL
;
;grep -E ^AB[AJ].*TO' 'webster-unabridged-dictionary-1913.txt'
Source: https://habr.com/ru/post/1689028/More articles:Greater time complexity of a recursive nested loop algorithm - javawhat does <{}> mean at the end of the extension in javascript? - javascriptReact Native Map Box Execution Не удалось преобразовать классы с помощью Dex/JarMerging - react-nativeMapbox: Can't add LocationLayer plugin to gradle - javakotlin reverse boolean safe casting - kotlinHow to read a line from the clipboard in the code name of one application? - androidIn ASP.NET MVC 5, how does the framework know that a POST request comes from its own web page? - c #IOS MIDI Graphic Events Using AudioKit - ioshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1689032/what-triggers-enis-to-be-created-for-aws-lambdas-accessing-vpc-resources&usg=ALkJrhjnL1cADiCNI-40_Ti1jZSS1v-jfAHow to remove data from Firestore using cloud functions - node.jsAll Articles