Help converting python to julia?

Hello There,
after my previous post I tried learning ReGeX to do the acronym thing I was trying to do.
I was able to write a python code for the same which works right !
Julia documentation was not clear to me…

Can you please help me ?

import re
def abbreviate(words):
    regex = "[A-Z]+['a-z]*|['a-z]+"
    return ''.join(word[0].upper() for word in re.findall(regex, words))

P.S: I’m a 15 year old and this the first time I’m doing Julia and RegEx

3 Likes
  1. for re.findall, search julia regex findall, check the first link is Find the index of all regex matches in Julia? - Stack Overflow . Take care that all matched stuffs are in type RegexMatch, you should use matched.match to get the exact matched string.

  2. for str.upper, you can type upper in Julia shell, and press TAB, to check if any available similar stuffs. Absolutely you’ll get

    help?> uppercase
    uppercase      uppercasefirst
    help?> uppercase
    search: uppercase uppercasefirst isuppercase
    
      uppercase(s::AbstractString)
    
    
      Return s with all characters converted to uppercase.
    
      Examples
      ≡≡≡≡≡≡≡≡≡≡
    
      julia> uppercase("Julia")
      "JULIA"
    
  3. word[0] shall be word.match[1], you know Julia uses usually 1-based index?

  4. ''.join, search julia join strings, and the 3rd result listed several titled links from Stack Overflow, I found this:

    Julia: concat strings with separator (equivalent of R's ... 1 answer  Aug 21, 2018
    

    Just click it and find out the use of join(strings, separator).

So,

function abbreviate(words)
     regex = "[A-Z]+['a-z]*|['a-z]+"
     return join([uppercase(word.match[1]) for word in eachmatch(Regex(regex), words)], "")
end
6 Likes

As you’re a very young person who just started learning about Julia, I’d give you such suggestions and methods to work with programming issues, instead of giving you the direct result.

4 Likes