Home > Back-end >  Regexp match all pieces of a string with `[0-9_] ` and skip optional `_[a-z0-9]{24}`?
Regexp match all pieces of a string with `[0-9_] ` and skip optional `_[a-z0-9]{24}`?

Time:10-18

Regexp match all pieces of a string with [0-9_] and skip optional _[a-z0-9]{24} ?

For instance,

hello word some_stuff other_stuff_607eea770b6d00003d001579 something

Should only capture/match

hello word some_stuff other_stuff something

Here's what I have but it still matches some part of [a-z0-9]{24}

/[a-z] (_[a-z] )?(?:[a-z0-9]{24})?/

CodePudding user response:

You're looking to match strings consisting of letters and underscores, whole words, with the end of the word at the end of the string, or a sequence of 24 more letters and/or numbers preceded by an underscore:

\b[a-z_] (?=_[0-9a-z]{24}|\b)
  • Related