-1

please can any one help me to break this code and explain it to me

this code as shown in the title

i know the output of it but i want to know how it works

REGEX : (?<!\\w)[tT]\\w+”)

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
Mach
  • 13
  • 2

2 Answers2

2

The parts of the regex are:

  • (?<!\\w) = "the preceding char is not a "word" char
  • [tT] = either "t" or "T"
  • \\w+ = "one or more "word" chars

Over all, it means "a word that starts with T and is at least 2 chars long"

Incidentally, this can be expressed more succinctly as:

\b[tT]\\w+

\b meaning "word boundary"

Bohemian
  • 412,405
  • 93
  • 575
  • 722
0
(?<!\\w)[tT]\\w+

(?<!\\w)==>negative lookbehind (there should not be a [a-zA-Z0-9_] behind t or T.

[tT]======>t or T.

\\w+======>any [a-zA-Z0-9_]+.(should be one or more)

Basically it captures words like

train,Train,@train,train,to,t121ka etc.

It will not capture

atrain

vks
  • 67,027
  • 10
  • 91
  • 124