C# Regex: Capture everything up to...

Posted by JamesBrownIsDead on Stack Overflow See other posts from Stack Overflow or by JamesBrownIsDead
Published on 2010-04-05T19:44:23Z Indexed on 2010/04/05 19:53 UTC
Read the original article Hit count: 292

Filed under:
|
|

I want to capture everything up to (not including) a # sign in a string. The # character may or may not be present (if it's not present, the whole string should be captured).

What would the RegEx and C# code for this by? I've tried: ([^#]+)(?:#) but it doesn't seem to work.

© Stack Overflow or respective owner

Related posts about regex

Related posts about c#