c# - Parsing Error while using Regex -


let me explain actual problem facing.

when searchstring c+, setup of regular expression below works fine. when searchstring c++, throws me error stating --

  parsing "c++" - nested quantifier +. 

can let me know how past error?

regexp = new regex(search_str.replace(" ", "|").trim(), regexoptions.ignorecase); 

first of all, believe you'll learn more looking @ regex tutorials instead of asking here @ current stage.

to answer question, point out + quantifier in regexp, , means 1 or more times previous character (or group), c+ match @ least 1 c, meaning c match, cc match, ccc match , on. search c+ matching c!

c++ in regex give error, @ least in c#. won't other regex flavours, including jgsoft, java , pcre (++ possessive quantifier in flavours).

so, do? need escape + character search literal + character. 1 easy way add backslash before +: \+. way put + in square brackets.

this said, can use:

c\+\+ 

or...

c[+][+] 

to c++. now, since have twice same character, can use {n} (where n number of occurrences) denote number of occurrences of last character, whence:

c\+{2} 

or...

c[+]{2} 

which should give same results.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -