I am trying to get some Regex to match and string that begins with ~ and ends with a space or the end of the line.
It's part of a Wiki Converter I'm cobbling together... I need to wrap anything that starts in ~ upto the next space (or EOL) in tags.
Example strings are:
"~Test" // matches Test
"~----" // matches ----
"~Test Bob" // match开发者_运维问答es Test
"~Test, Bob" // matches Test,
"Some ~Test Bob" // matches Test
"Some ~Test" // matches Test
Thanks
(?<=~)[^\s]+
Read as "look behind for a tilde, then match anything after that except for whitespace."
(?<=~)\S+
Same as the other answer, but better match for non-whitespace.
Or, simpler,
~(\S+)
If you are using group anyway
精彩评论