✅ help with regex
I'm trying to learn regex, have watched multiple tutorials and checked multiple websites, but can't fully grasp how to use it for my specific situation.
I want to find and retrieve a certain part out of a string: the word that follows an @.
currently I have this:
^@[a-zA-Z0-9]+$
Here are some example cases:
word @something
-> true
@something
-> true
word@something
-> false
I'd like to be able to retrieve the @something
from those examples, whilst ignoring the rest. Would my regex work? I've tried it with this website (https://regexr.com) but it doesn't seem to work...RegExr
RegExr: Learn, Build, & Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).
26 Replies
Your use of ^ is a problem
It means the string must start with an @
Oh.
I just thought it had to all start with ^
^ means "the start of a line"
similarly $ means "the end of a line"
it's useful if you're looking for say, a particular kind of message in a huge log file
also, take a look at
\B
Is there any site that lists all the filters?
The Microsoft site seems to be missing some
https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference
What's it missing?
Regular Expression Language - Quick Reference
In this quick reference, learn to use regular expression patterns to match input text. A pattern has one or more character literals, operators, or constructs.
Oh damn that's a good site
I didn't find that one
I was using the regex page
I think that has a link to the quick reference
Anyway, if you really want to learn regex the book Mastering Regular Expressions is the bible
Huh. Guess I'm blind then. Alright I'll use the quick reference and try to make a new filter
Then I'll get back to here
Thanks mates
Update: I got this, but I've got one last thing to solve.
@[a-zA-Z0-9_]{4,25}
it checks for the thing after the @, but I still need to ensure that there is nothing in front of it. can I do [empty space OR start of string]? is there an OR expression that I can use? (I think it might be the | constructor, so maybe (/s|^)@[a-zA-Z0-9_]{4,25}
?
also, how would I extract that from the string? since regex only returns a boolChucklesTheBeard#6079
also, take a look at
\B
Quoted by
<@!229282705374838794> from #help with regex (click here)
React with ❌ to remove this embed.
for one.
.Matches()
for multipleah alright, thanks
I don't fully get this
from what I understand, it means that there has to be a letter before that?
play with it
alright
If you need to detect an actual space, I think you'll need to use a capture group instead so as to avoid including that space in the match
Match().Groups[0].Value
or something similaralright
nah I think my method or the \B method works
still don't fully understand what it does but from my random testing it seems to work
test against
foo@@bar
if that can appear in your inputnot triggered, as it's supposed to
neat
I'm gonna try and give the code a test instead of that online site
but my software is screaming at me for some reason
I'll need to figure that one out
I find the mute button helps! 🙂
I prefer the volume wheel on my headphones
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.