Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
275 views
in Technique[技术] by (71.8m points)

javascript - Regular Expression for number and dash

Currently I write the regex like this: /^([d+]*-)+([d]*-)+([d])*$/

I want the result follow this pattern 00-123-456-789 or 00123456789 (dash between number group or no dash at all)

  • not 00-123--457-789
  • or -00-123-456-789-
  • or -00123456789-
  • or 00-123-456-789-

How can I modify the regex to matches the pattern above?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try something like this

/^(d+-?)+d+$/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...