Regex + vs *. What is the standard? -


i use regex quite bit find , replace, , want use best practices as possible.

i understand difference between + , * characters. reference * find matches specified phrase, , + find last instance of specified phrase.

that being said, when regex phrases on internet, see lot of people using + feel using *. standard use + instead of * on generic regex phrases or there convention missing?

the site you've linked great, you're misunderstanding definitions of * , +. essentially, * means "zero or more," + means "one or more."

in other words:

  • x* means "any number of x characters in row, or possibly none @ all."
  • x+ means "any number of x characters in row, at least one."

so x+ equivalent xx* (or x*x). both have infinite upper limit, different lower limits.

as far 1 standard/best practice, answer "neither," since both have different meanings. however, if you're trying match 1 or more of something, it's better use x+ xx*. both correct, first shorter , more readable.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -