-1

The minimum string length should be 3 and it should not contain # and ^ in the string

I tried with /([a-zA-Z][^a-zA-Z#^]*){3,}/, It's working on https://regexr.com, but its not working all testing tools like https://www.regextester.com .

mousetail
  • 7,009
  • 4
  • 25
  • 45
manishk
  • 34
  • 2

1 Answers1

2

EDITED: ^(?![^a-zA-Z0-9])[^#^]{3,}$ should do the work if you just want to:

  • match a string containing characters except # and ^
  • has a length of at least 3 characters
  • only let alphanumerics be the first char
Henryc17
  • 851
  • 4
  • 16
  • It is taking space as a first char, but it should not be allowed – manishk Nov 02 '22 at 11:30
  • 1
    @manishk that's not what your question said: "*The minimum string length should be 3 and it should not contain # and ^ in the string*" and [you didn't clarify when you were asked what it should contain](https://stackoverflow.com/questions/74285574/and-should-not-match-in-this-regular-expression-a-za-za-za-z3-i/74285666?noredirect=1#comment131149083_74285574). Please think *carefully* about your questions before you ask them. You've been given an answer based on what you asked, not based on information that was not presented. – VLAZ Nov 02 '22 at 11:33
  • @VLAZ it is a common thing, string will not take the first char as a space normally – manishk Nov 02 '22 at 11:43
  • @manishk, strings in programming have a very large chance to start with a space character, especially when you trying to combine two strings: `"Posted"+" at yesterday"`. It's not such "a common thing". If you wish to not include space has first char, you should specify the requirements in the question, pls review my edit. – Henryc17 Nov 02 '22 at 14:50
  • @Henryc17 sorry for the one more test case, actually it should start with a number or char only, not with special char, in between of string special char we can use except for # and ^, thanks for support! – manishk Nov 04 '22 at 10:19
  • @manishk, Ive made another edit, pls take a look. – Henryc17 Nov 04 '22 at 12:23