Seanny123
Seanny123

Reputation: 9346

Convert Regex match into string

I have a RegexMatch object which I'd like to convert into a string:

mm = match(r"(?<=Info: ).+", "Info: Kim")

However, I can't figure out how to convert it into a string. The following does not work:

How is this supposed to be accomplished?

Upvotes: 5

Views: 826

Answers (2)

张实唯
张实唯

Reputation: 2862

You can also use capturing group and index:

julia> mm = match(r"((?<=Info: ).+)", "Info: Kim")
RegexMatch("Kim", 1="Kim")

julia> mm[1]
"Kim"

Upvotes: 2

Seanny123
Seanny123

Reputation: 9346

The field .match will convert the match object into a string.

mm.match

Upvotes: 4

Related Questions