0

How to capture any alphabet and any numeric into one group using regex. I use basic regex to capture it, but every single character become a new match. According to image below, I want the result like this:

match 1 = Q
match 2 = m
match 3 = C
match 4 = t2
match 5 = result (this word 'result' just an example, it can be replaced by any word)

enter image description here

Kevin
  • 49
  • 10
  • Do you want to match any word? `\w+`? – Wiktor Stribiżew Jul 30 '18 at 16:03
  • 1
    Why do you not want to match `c` ? Is it because its between two `*` ? – Paolo Jul 30 '18 at 16:05
  • @WiktorStribiżew basically I want any match that close to another match will join to a new match, not become two or more separated matches. – Kevin Jul 30 '18 at 16:07
  • 1
    What is the exact rule for matching? Match 1+ walphanumeric chars that..... Please complete – Wiktor Stribiżew Jul 30 '18 at 16:09
  • @UnbearableLightness Sorry, I want to match c too. I'll update it. I also use any other character like *, +, -, /, ^, [, ]. That's why I'm using \w and \n to capture that I think more simple. It's not a must anyway. – Kevin Jul 30 '18 at 16:11
  • 3
    Read a tutorial about regex to learn the basics, you will waste less time. – Casimir et Hippolyte Jul 30 '18 at 16:14
  • Sure, I'll read it :) – Kevin Jul 30 '18 at 16:18
  • @WiktorStribiżew How this question is a duplicate? All the answers of previous questions are very different with this question's answer. Not just the answer, the question itself is not same with this question. – Kevin Jul 30 '18 at 18:09

1 Answers1

1

Use a quantifier + for one or more

/[[:alnum:]]+/

See demo at regex101

Be aware that \n matches a newline and not a number. \d would be the short for digit.
\w (word character) matches [A-Za-z0-9_]. It includes \d already .

bobble bubble
  • 11,968
  • 2
  • 22
  • 34