user14881255
user14881255

Reputation:

Regex match strings with different values

for i,v in array

for i   ,    v      in array

for i , v in array

for i,         v in array

for i,v               in array

for  i, v in array
for[\s+,.](.+)

https://regex101.com/r/Vd3w7C/2

How i could match anything after the v

but

i,v, and in array will have different values

i mean something like: for ppp,gflgkf heekd gfvb

Upvotes: 0

Views: 138

Answers (1)

The fourth bird
The fourth bird

Reputation: 163352

You could use

\bfor\s+[^\s,]+(?:\s*,\s*[^\s,]+)*\s+(.+)

The pattern matches:

  • \bfor\s+ Match for and 1+ whitespace chars
  • [^\s,]+ Match 1+ times any char except a whitspace char or ,
  • (?: Non capture group
    • \s*,\s*[^\s,]+ Match a comma between optional whitespace chars, and match at least a single char other than a comma or whitespace chars
  • )*\s+ Close the group and optionally repeat it followed by 1+ whitespace chars
  • (.+) Capture 1+ times any char except a newline in group 1

See a regex demo.

Upvotes: 1

Related Questions