Regex to choose something between #OnlinePopup and _
3 answers
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
+2
source to share
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.
0
source to share