0

I am new to using regex and am trying to write 2 seperate regular expressions.

One should not allow anything other than letters after the last # and must not have fewer than 2 letters after the last #.
Passing ex: #12#abc
Currently my regex doesn't allow anything but letters after the # and I can't get the rest to work. I tried using {2,}.
Here's my attempt: ^[^#]*[#][a-zA-Z]*$

The second must not allow "&$" or "$&" after # (only 1 # is allowed in the string).
Failing ex: abc#$&ab
Here is what I was trying that is not working: ^[^#]*[#][^&]*[^\$]+$

Any help is appreciated.

YakovL
  • 5,213
  • 10
  • 46
  • 71
user1807815
  • 57
  • 2
  • 12
  • 1
    Looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Jan 09 '20 at 01:12
  • I have edited and added the expressions I had written – user1807815 Jan 09 '20 at 02:12
  • *I tried using `{2,}`. `^[^#]*[#][a-zA-Z]*$`* - but I see you used `*`. Use `{2,}`: `[a-zA-Z]*` => `[a-zA-Z]{2,}`. As for the 2nd one, use `^[^#]*#(?!.*(?:&\$|\$&))[^#]*$` – Wiktor Stribiżew Jan 09 '20 at 06:15

0 Answers0