❔ Regex expression to find the last occurrence in a string
Looking for a regex expression to find the last occurrence of any of the following characters ( + - * \ in a given string.
I need to get the text following the last occurrence of any of those characters and return a list of auto complete suggestive text from a list of possibilities I have built.
23 Replies
[(+\-*\\]([^(+\-*\\]*)$
something like this should work
I'm not sure everything is escaped properly
the first group (index 1) is your textThanks Anton, could you break it down and explain if you have time?
I get the stuff in [] looks for characters what is the stuff in ([]) ?
will try it out real quick
Also don't quite understand the ^ * and $ what they mean
regex101
regex101: build, test, and debug regex
Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET.
ok so ^ says at start, * is 0 or more times and ? is at end?
so the stuff in the first [] says match this .. and the stuff in () basically says under these conditions?
reading the manual on regex but its a bit cryptic to me lol
[] means match what's inside
() make a group so you can take them by index later
ahh so group by?
caret within [] inverts it
* means 0+ times
$ means end of string
so that regex matches one of your characters, then 0+ not of your characters, at the end of input
i meant match one of the characters inside
but [] also has range syntax, so you have to escape symbols that would otherwise make a range, I think
e.g. [a-z] matches the range from a to z rather than a, - or z
[a\-z] would match one of these 3
i think
ah also I should mention
lol so many rules
put the regex string into a raw string literal
aka a verbatim string
@"" ?
@"string here"
yeah k
if you don't, you'll have to escape backslashes
an extra time
thanks man. it seems to be working for my purpose. I'll pop it into my code and see how it works, then I can move on to provide suggestions 🙂
I am building a list of suggestions based off methods I am reflecting on in a Namespace so when anyone adds functions to that namespace it automatically picks up the new functions and their parameters
So I can provide suggestions while people are typing
kind of like home brew intellisense lol
why aren't you using a library for this
well
seems like too much work
If I knew of a library i would.. but
there are custom elements in the list
Roslyn
make it read your assembly definitions or the source code dierctly
so like someone using the software. They create a step for a machine to do something and the intellisense has to pickup on those past activities so it can reference past steps
That's pretty cool i'll have to look into it
I always hear the name but never used it lol or knew what it was
it's the whole compiler as a library
in fact all modern c# compilers are based on that
nice
wups my divide by operator was backwards lol i typed \ instead of /
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.