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.
{x,y}
x minimum amount match , y maximum amount match. can put 1 digit{4}
match 4 occurrences.+
means 1 or more, same{1,}
*
means 0 or more, same{0,}
?
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:
- regular expression quick start on www.regular-expressions.info
- .net framework regular expressions on msdn.microsoft.com
Comments
Post a Comment