regex - How to totally compare a string with regular expression in objective C -


i trying see via reg ex if user gave correct input(user should give complex number), , dependent on input program should give action.

so far have 3 reg expressions comparison:

@"([-]?[1-9][0-9]*[+|-][1-9][0-9]*i)+" @"([-]?[1-9][0-9]*)+" @"([-]?[1-9][0-9]*[i])+" 

in case want see if complex number given correctly, use first reg ex.

if not given correctly want use other 2 expressions see if user used abbreviations input.

the problem if user gives 3i in program real number, because of reg ex. reg ex testing if part of string correct, , want know if entire string correct.

for example if type 3i3 , if use third expression, result true, , want true 3i.

if want make regex matches entire string, add ^ , $ anchors it:

@"^([-]?[1-9][0-9]*[+|-][1-9][0-9]*i)+$" @"^([-]?[1-9][0-9]*)+$" @"^([-]?[1-9][0-9]*[i])+$" 
  • ^ @ beginning means match must start @ beginning of input string
  • $ @ end means there must no characters in input after match

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -