-1

I have text like this

Example: "visa code: ab c master number: efg discover: i j k"

Output should be like this: abc, efg, ijk

Is there a way, I can use Grok pattern match or Reg EX to get 3 characters after the ":" (not considering space) ?

MritiYogan
  • 126
  • 6
  • There is, but you will need to give more detail. Can you give an example of input and what you want the resulting match to be? – vs97 Feb 25 '22 at 22:45

1 Answers1

-1

You can start with this:

>>> import re
>>> p = re.compile(r"\b((?:\w\s*){2}\w)\b")
>>> re.findall(p, "visa code: ab c master number: efg discover: i j k")
['ab c', 'efg', 'i j k']

But you have more work to do. For example, nobody can guess what you mean - exactly - by "characters".

Beyond that, pattern matching systems match strings, but do not convert them. You'll have to remove spaces you don't want via some other means (which should be easy).

Tim Peters
  • 67,464
  • 13
  • 126
  • 132