user3523657
user3523657

Reputation: 37

Regular expression to get data between semicolon

I have the following text:

lemap;Brsjmnb008528;Ask Toolbar;APNLLC;09/04/2014

I would like build a regular expression to get complete words before first semicolon, another one to get only all the words between first and second semicolon, etc.

Like this for the first use case:

[^;]*

Any suggestions?

Upvotes: 0

Views: 16124

Answers (4)

LightTechnician
LightTechnician

Reputation: 287

The correct answer is [^;]+ Using [^;]* will match the nulls also

Upvotes: 1

bartektartanus
bartektartanus

Reputation: 16080

Try this regular expression:

^[^;]*

to get first word. ^ at the beginning matches the beginning of a string.

Upvotes: 0

Toto
Toto

Reputation: 91528

With this one:

^([^;]+);([^;]+);

you'll have the first word in group 1 and the second in group 2.

Upvotes: 1

gitaarik
gitaarik

Reputation: 46370

Your regex:

[^;]*

should work, but maybe you just need to capture what you match:

([^;]*)

Upvotes: 1

Related Questions