Regular expression not matching string

adviner

I'm trying to figure out the following regular expression:

/^[0-9]{2}-[0-9]{2,3}[a-zA-z]{0,1}/g

In my example.
The following should pass: 00-45, 00-333, 33-333a, 55-34a The following should fail: 33-3333, 22-22dd, 22-2233

Here is my screenshot:

enter image description here

But the once that should fail arent failing. In my javascript code I just do a test:

var regExp = new RegExp(exp);
if(regExp.test(test1))
    alert('pass');
else
    alert('fail');

Is there a way for the regular expression to test the entire string? Example 33-3333 passes because of 33-333, but since there is another 3 I would like it to fail since the fourth 3 would be tested against the character rule?

anubhava
  1. You are missing end anchor $ in your input
  2. A-z inside character class will match unwanted characters as well, you actually need A-Z
  3. {0,1} can be shortened to ?

Try this regex:

/^[0-9]{2}-[0-9]{2,3}[a-zA-Z]?$/

RegEx Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Regular expression matching with string

From Dev

Regular expression for matching string

From Dev

regular expression not matching for string

From Dev

Regular Expression not matching a string as expected

From Dev

returning string matching regular expression

From Dev

Why is the regular expression not matching the string?

From Dev

Regular expression - matching inside a string

From Dev

returning string matching regular expression

From Dev

Regular expression - matching inside a string

From Dev

regular expression evaluation in string matching

From Dev

Regular Expression at the end of the string not matching

From Dev

Regular Expression: matching plural cases at end of string

From Dev

Matching multiple words within a string with regular expression

From Dev

String pattern matching with regular expression in java

From Dev

Matching word using Regular Expression in a string

From Dev

Regular expression not matching specific string and strict test

From Dev

Regular Expression for Matching String not beginning or ending with alphabet

From Dev

Matching double space in regular expression string with BootstrapValidator

From Dev

Regular expression for multiple matching in a hierarchical string

From Dev

Matching a string with regular expression returns null

From Dev

Regular Expression Help - Difficulty Matching String

From Dev

Replace string by matching using regular expression python

From Dev

Matching digits and text in a string using regular expression

From Dev

Matching regular expression at the end of the string with Python 2.7.13

From Dev

Regular Expression Not Matching Correctly

From Dev

NGR Regular Expression Matching

From Dev

Regular expression matching (Javascript)

From Dev

matching regular expression in python

From Dev

Regular expression for matching a sequence?

Related Related

  1. 1

    Regular expression matching with string

  2. 2

    Regular expression for matching string

  3. 3

    regular expression not matching for string

  4. 4

    Regular Expression not matching a string as expected

  5. 5

    returning string matching regular expression

  6. 6

    Why is the regular expression not matching the string?

  7. 7

    Regular expression - matching inside a string

  8. 8

    returning string matching regular expression

  9. 9

    Regular expression - matching inside a string

  10. 10

    regular expression evaluation in string matching

  11. 11

    Regular Expression at the end of the string not matching

  12. 12

    Regular Expression: matching plural cases at end of string

  13. 13

    Matching multiple words within a string with regular expression

  14. 14

    String pattern matching with regular expression in java

  15. 15

    Matching word using Regular Expression in a string

  16. 16

    Regular expression not matching specific string and strict test

  17. 17

    Regular Expression for Matching String not beginning or ending with alphabet

  18. 18

    Matching double space in regular expression string with BootstrapValidator

  19. 19

    Regular expression for multiple matching in a hierarchical string

  20. 20

    Matching a string with regular expression returns null

  21. 21

    Regular Expression Help - Difficulty Matching String

  22. 22

    Replace string by matching using regular expression python

  23. 23

    Matching digits and text in a string using regular expression

  24. 24

    Matching regular expression at the end of the string with Python 2.7.13

  25. 25

    Regular Expression Not Matching Correctly

  26. 26

    NGR Regular Expression Matching

  27. 27

    Regular expression matching (Javascript)

  28. 28

    matching regular expression in python

  29. 29

    Regular expression for matching a sequence?

HotTag

Archive