visual studio 2010 - Match two whole words in Regex -


i struggling find solution matching 2 successive whole words using regular expression. have text box user can type in search criteria, enclosed quotations exact matches. quotes , space (if any) replaced regex expressions. here example:

user enters: "apple orange"

converted to:

\bapple\w+(?:\w+\w+){1,6}?orange\b 

then, regex match based on converted criteria. instructions www.regular-expressions.info/near.html

maybe going entirely wrong way? using visual studio. appreciated.

if want exact match when user uses quotes, should remove quotes , straight string comparison (equality, not contains)

update:

based on comments below, same thing single word match:

single word:

\bapple\b

double word

\bapple orange\b

the idea user enters in search term , match that, wouldn't doing pattern matching term itself, boundaries of (the \b wrapped around it). there's no reason touch search term (all stuff in-between apple , orange trying do) because space inbetween 2 part of search...unless wanting make bit flexible..for example, if user enter in "apple[lots of space here]orange" count single space, do

\bapple\s+orange\b

..but you're kind of deviating whole "exact match" theme...

sidenote: said in comment "crabapple orangecrush" did not want "apple orange" match. why use \b word boundaries. imo if me, allow match. or @ least, offer kind of option search in manner.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -