b_andries
b_andries

Reputation: 25

How to find a specific regular expression patern but exclude the middle character

my testsentence is for example 'hello random-word testing'

I would like to find the regular expression to extract 'random word' but explude the dash ('-')

I tried [a-z]+[^-][a-z]+, but this also selects the words in front and at the end

Thanks

Upvotes: 1

Views: 28

Answers (1)

CollinD
CollinD

Reputation: 7573

You could do it like this

([a-z]+)[-]([a-z]+)

At that point $1 and $2 will contain your words. Alternatively

([a-z]+[-][a-z]+)

At that point, just do a replace on $1 for '-' -> ' '

Upvotes: 1

Related Questions