These regexes are in the same format as in Julia (Perl-compatible regular expressions) so you can use them without converting anything. The only catch is here you have a testex string with multiple lines, and you want the regex ^...$ to match a whole line rather than a whole string. For this you need to add the m flag to the regex by writing it r"..."m.
Note that the first regex starts with ^(?<val>-?[0-9.,]+). This will only match lines that start with a dash - (optional), followed by a non-zero number of digits/periods/commas. This can match the second line which starts with 999999998, but not the first line which starts with C.
On the other hand the second regex starts with ^(?<val>[[:graph:]]+). This will match any line that starts with graphical characters (alphabetic, numeric or punctionation). This can match both lines, so let’s use this one:
testex = "Codes999999999 = N.I.U.\n999999998 = Missing. (1962-1964 only)\nValues can be negative.\n\nThe Census Bureau applies different disclosure avoidance measures across time for individuals with high income in this variable. Detailed explanations of these methods, topcodes, and replacement value and swap value thresholds are available here."
regex = r"^(?<val>[[:graph:]]+)(([[:blank:]]+[[:punct:]|=]+[[:blank:]])+)(?<lbl>.+)$"m
We can use eachmatch as suggested by @danielwe to match all the lines with a single call. Each mach can be indexed with the capture names (val and lbl) that we have defined in the regex. We use this to collect the values we want:
julia> matches = [[m[:val], m[:lbl]] for m in eachmatch(regex, testex)]
2-element Vector{Vector{SubString{String}}}:
["Codes999999999", "N.I.U."]
["999999998", "Missing. (1962-1964 only)"]
Then to have the codes in a single array:
julia> stack(matches, dims=1)
2×2 Matrix{SubString{String}}:
"Codes999999999" "N.I.U."
"999999998" "Missing. (1962-1964 only)"
If you want to put the result in a data frame, it’s better to gather the codes as a vector of named tuples rather than a vector of vectors:
using DataFrames
julia> matches = [(value=m[:val], label=m[:lbl]) for m in eachmatch(regex, testex)]
2-element Vector{@NamedTuple{value::SubString{String}, label::SubString{String}}}:
(value = "Codes999999999", label = "N.I.U.")
(value = "999999998", label = "Missing. (1962-1964 only)")
julia> DataFrame(matches)
2×2 DataFrame
Row │ value label
│ SubStrin… SubStrin…
─────┼───────────────────────────────────────────
1 │ Codes999999999 N.I.U.
2 │ 999999998 Missing. (1962-1964 only)