Short Code Regex
I wrote a regex according to the shortcode in a format like:
[playername Le'Veon Bell]
Here's the regex:
\[playername\s+(?<name>[\w \-\'\β]+)\s*\]
I know that regex is struggling with one quote in the player name. I've tested the regex here and it seems to work but doesn't find a match when I run the code from my web app.
source to share
Based on the information you provided, I believe it \[playername\s+(?<name>[^]]+?)\s*\]
should work.
The only real difference is the capture group [^]]+
, which matches any character that is NOT a ]
. This will effectively grab anything after [playername
before the first ]
. It will break if you have nested parentheses.
source to share
Not knowing more about your script, which is hard to say for sure, but from what you have, I would say you need to switch to something similar?
\[playername\s+(?<name>[^\]\s]*)\s+\]
This will match anything that doesn't have a square bracket or space in it, so it seems like what you're actually trying to do. I would personally be tempted to remove the whitespace conditions, simply on the basis that the name may have a place in it. You can always call any version of your C # language string.Trim()
after the fact.
Note, of course, that this is not exactly the same as what you are doing: you are explicitly limiting characters. But it looks like you are trying to limit any text anyway.
source to share