Tanya Arora
Tanya Arora

Reputation: 113

Match letters before matching a space character in regex - Javascript

I have this regex -: /@[a-zA-Z ]+/g; Clearly, this would match @abs as well as it would match
@ abs. But I dont want the latter to match cuz it has a space character before a letter. My regex should only match those where space is preceeded by a letter.

How to do that?

Upvotes: 2

Views: 139

Answers (2)

JimmyMcHoover
JimmyMcHoover

Reputation: 854

putting [a-zA-Z] after the @ would force a letter there: /@[a-zA-Z][a-zA-Z ]*/g;

Upvotes: 4

hjelpmig
hjelpmig

Reputation: 1455

You accidently added a space in your regex after Z

/@[a-zA-Z ]/

Upvotes: -1

Related Questions