regex - .net Howto find substrings with placeholder -


i've got list of strings, , want check every string if contains substring.

problem is: there should placeholders allowed.

e.g.: i'm searching "customer-id", "customer id", "customers id" -> search string looks this: "customer{2}id" (whereas {2} stands number of placeholder characters -> between 0 , 2).

of course won't work

teststring.indexof("customer{2}id") 

tried also:

dim r new regex("customer??id") 

but throws nested qualifier something exception. not geek in regular expressions appreciate help.

? quantifier in regular expressions (and not place holder single character). means quantifies preceding element. can character, character class or group.

there exist 4 quantifiers in regex.

  1. {x,y} x minimum amount match , y maximum amount match. can put 1 digit {4} match 4 occurrences.

  2. + means 1 or more, same {1,}

  3. * means 0 or more, same {0,}

  4. ? means 0 or one, same {0,1}

i think need like

customer.{0,2}id 

. special character in regex , matches character (except newlines)

so regex match strings like:

customerid
customer id
customer-id
customer#+id
customerxxid

you can replace . more defined character class, e.g. if want allow space , hyphen, create own character class , add characters want allow.

customer[ -]{0,2}id 

this regex match strings like:

customerid
customer id
customer -id
customer- id
customer--id

further information:


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -