1

My input is for example "ghj, klj! ab-CDE-fg_hi".

When I use \w+ pattern I get ["ghk", "klj", "ab", "CDE", "fg_hi"].

I need to get this array ["ghk", "klj", "ab", "CDE"].

How can I get the wanted output?

Jan
  • 42,290
  • 8
  • 54
  • 79
Ara Galstyan
  • 486
  • 1
  • 4
  • 11
  • 1
    There's more here you are not telling us. For example, you are splitting on `-` and spaces, and dropping `!`'s and `,`'s, which means you need to describe the problem domain more for us. Sure, you could do some regex like `[^_]*` to find matches that don't have an underscore, but we need more info on what we can do since what I said will not help solve the problem based on the input and output provided. Also, is this for a particular language? – Water May 01 '21 at 16:44
  • Thanks for the comment. We should only match the parts of string that contain English letters. So we should ignore any symbols, underscores, hyphens. I will use this regex in JS. – Ara Galstyan May 01 '21 at 16:49

1 Answers1

2

You are looking for word boundaries and a character class:

\b[a-zA-Z]+\b

See a demo on regex101.com.

Jan
  • 42,290
  • 8
  • 54
  • 79