Sangram Singh
Sangram Singh

Reputation: 7191

regex:- begin with 'abc' and end immidiately when find 'xyz'

regex for begin where find 'abc' end where first find 'xyz'.

I can write:- var regex = /abc/ to match the exact abc.

I'm trying to read more. Any help is appreciated.

following tutorial

Upvotes: 0

Views: 182

Answers (2)

anubhava
anubhava

Reputation: 785256

You can use this regex:

var regex = /\babc\b.*?\bxyz\b/;

\b is for word boundaries to make it match abc and xyz specifically not aabc or xyz123

Upvotes: 1

Tim Pietzcker
Tim Pietzcker

Reputation: 336198

The simplest way would be

/abc.*?xyz/

.*? means "Match any number of characters, as few as possible.

Upvotes: 1

Related Questions