Reputation: 11251
I have this variable 1874;#Bob Williams. I tried this and it should give me 1874 but it's giving me the entire variable. Any idea?
(?<=\w+;)
Upvotes: 1
Views: 375
Reputation: 24419
Whatever tool/engine you're using is removing what it matches and returns what remains after removal, so this should work for you: ;.+
Upvotes: 2
Reputation: 23531
A bit off topic but you dont need a regex for this. Not at all. Use Substring
instead:
var s = "1874;#Bob Williams";
s = s.Substring(0, s.IndexOf(';')); // If your input might not contain a semi colon, check the return of IndexOf
// s == "1874"
If you are writing .NET
code as your tag show, use this.
Upvotes: 1