user2335923
user2335923

Reputation: 43

Regex substring

I'm trying to select a substring using regex and I'm going round in circles. I need to select everything before the first "_".

exampale URL - GI_2013_JUNE_10_VOL3_LASTCHANCE

So the result Im looking for from the URL above would be "GI". The text before the first "_" can vary in length.

Any help would be much apprecited

Upvotes: 0

Views: 832

Answers (2)

fge
fge

Reputation: 121840

The regex would be:

^[^_]+

and grab the whole regex match. But as a comment says, using a substring function is more efficient!

Upvotes: 1

Thomas Kelley
Thomas Kelley

Reputation: 10302

^[^_]*

...is the expression you're looking for.

It basically says: Select everything that is not an underscore, starting at the beginning of the string.

http://regexr.com?356in

Upvotes: 0

Related Questions