Regular Expressions: Positive Lookahead and Word Border question
        Posted  
        
            by Inf.S
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Inf.S
        
        
        
        Published on 2010-03-18T18:20:41Z
        Indexed on 
            2010/03/18
            18:31 UTC
        
        
        Read the original article
        Hit count: 465
        
Hello again Stackoverflow people!
Assume I have these words: smartphones, smartphone
I want to match the substring "phone" from within them. However, in both case, I want only "phone" to be returned, not "phones" in the first case. In addition to this, I want matches only if the word "phone" is a suffix only, such that:
fonephonetics (just an example) is not matched.
I assumed that the regex
(phone([?=s])?)\b
would give me what I need, but it is currently matching "phones" and "phone", but not the "fonephonetics" one. I don't need "phones". I want "phone" for both cases.
Any ideas about what is wrong, and what I can do?
Thank you in advance!
© Stack Overflow or respective owner