squill25
squill25

Reputation: 1208

Regex split into words and punctuation/symbols

I have the following input:

func add(var a:Int, var b:Int) -> Int
{
    return a + b
}

I'm using this Regex \s*\b\s* which I found online which is supposed to split up words and punctuation/symbols. I tried it and it split up the input to

func
add
(
var
...

Which is working exactly how I want it to, until it finds the -> sign, where it outputs

:
Int
) ->
...

Everything else works fine but I would like it to output

)
-
>

instead.

How can I achieve this? Thank you in advance.

Upvotes: 1

Views: 216

Answers (1)

hashier
hashier

Reputation: 4750

Since I don't exactly know which version of regexp you are using and which command you are running to verify it I can't be completely sure that this solves your problem, but it should.

\s*(\b|[->])\s*

Upvotes: 1

Related Questions