Regex to choose something between #OnlinePopup and _
Can anyone show me a regex to select # OnlinePopup_AFE53E2CACBF4D8196E6360D4DDB6B70 so that it will accept#OnlinePopup
~DCTM~dctm://aicpcudev/37004e1f8000219e?DMS_OBJECT_SPEC=RELATION_ID#OnlinePopup_AFE53E2CACBF4D8196E6360D4DDB6B70_11472026_1214836152225_6455280574472127786
Note. Below is the .NET Regex syntax, change it to your liking.
Following:
#[^_]+_[^_]+
will match:
- Hash
- One or more characters before underscore
- Underline
- One or more characters before underscore
If the first bit is constant and you want to be more specific, you can use:
#OnlinePopup_[A-F0-9]+
This will match
-
OnlinePopup_ (exactly)
- One or more hexadecimal characters up to a non-hexadecimal character
A simple match between the first "#" and the first or last "_" will not work for your example, since the string you want to return has an underscore in it. If all the text you want to match has only one underline in it, you can use this regex:
/(#[^_]+_[^_]+)/
This corresponds to an octotorp (#) followed by two lines that do not contain an underscore, separated by a single underscore.
Something a little simpler:
(\#OnlinePopup_.*?)_
Assuming your text starts in C # and ends in _