c# - regex match but not include in group -
i'm doing little regex recognize complex number. need in c# school program. must recognize complex numbers like: 3+5i 3+5k 4-i5 6+f7
so, imaginary part can have char behind or ahead value. wrote regex:
(?<reale>[+-]?\d+)(?<immaginaria>[+-]\d+[a-za-z]|[+-][a-za-z]\d+)
the problem is, when take group called "immaginaria" have got imaginary part char (like or j) , i'd without.. found solution of using look-ahead , look-behind but have got problem while trying implement in regex (it's first regex write)
(?<reale>[+-]?\d+)(?<immaginaria>[+-]\d+(?=[a-za-z])|[+-](?=[a-za-z])\d+)
i modified first attempt little bit separate sign , value of imaginary part, can concatenate them later after successful match:
(?<reale>[+-]?\d+)((?<immaginariasign>[+-])(?<immaginaria>\d+)[a-za-z]|(?<immaginariasign>[+-])[a-za-z](?<immaginaria>\d+))
Comments
Post a Comment