tags:

views:

98

answers:

3

Hi all,

I am wondering , how would i match the words "SAN JOSE" in a string "I love SAN JOSE but JOSE does not like it " so in essence i do not want the the word Jose to be matched but SAN JOSE should be matched together.

any ideas . thanks

+6  A: 

You don't need regular expressions in this case. You didn't specify a language, but most of them support basic string matching. Just search for 'san jose' in case-insensitive mode.

NullUserException
A: 

You need to escape the space:
/SAN\ JOSE/

Dani
No, he doesn't need to.
zneak
A: 

You need a look-ahead assertion:

/san (?=jose)/
Kolo32
Asker specified that "SAN JOSE" be matched. With the look-ahead, it would only match "SAN".
jdmichal
He says "i do not want the the word Jose to be matched but SAN JOSE should be matched together." It's exactly what look-ahead assertions are for.
Kolo32
@Kolo You misunderstood the question
NullUserException
And how do you understand him?
Kolo32
Hrm. I see where that could be confused. Removed the down-vote, though I personally think that he means for the pair to be matched, but not "JOSE" alone. The question title and the first sentence seem to make that clear.
jdmichal
`match exactly two words and not one of the the two`
so i did try what kolo32 suggested and surprisingly the match found is only SAN out of SAN JOSE . I am using php and jdmichal's both comment is right . i want both the words to be matched for the regular expression
SANJAY RAO