Removing characters with Regex

I'm trying to remove some characters from a string using search and replace and Regex.
I find the Regex learning curve a bit overwhelming...

For instance:
HFT-COOL (Surf) - Codingweb
HFT-SURFER (Surf) - Codingweb

would deliver COOL and SURFER.
So the 1st four characters and all characters after the first space need to be removed (including the space itself). Any pointers? Thank you!

\-(.+?)[space]

Just change [space] to a space.

Thanks, a step further! So the solution is Group 1. How do i refer to Group 1 in the "replace with" section?
Tested on https://regex101.com...

$1

(Click on the Gear icon of the action you're using for more help.)

Hmmm, that doesn't work.

Lots of ways to skin this cat.
If you want to make sure you get the text after "HFT-", then this will work.
It also allows for multiple spaces or tabs after the key text.

==UPDATED==: 2020-01-04 14:10 GMT-6
Allow for searched text to be single or multiple lines

Search For:
(?m)^HFT-(.+?)\h+.+$

Replace with:
\1

For details, see regex101: build, test, and debug regex

1 Like

Thanks!!!

Just made an update to handle multiple lines.

Even better! Thanks!

1 Like

Ah, Discourse stripped the leading slash. I've edited the original post to restore it.

The way to avoid Discourse changing your text is to enclose in back quotes like:

  `my text`

Found a cool website to help learn Regex. Maybe someone finds it useful in the future https://regexone.com

1 Like

There are several good tutorial sites for RegEx, but I do like the interactive learning feature of this one. Doing is always the best method for learning.