I am new to this forum. I need help in defining the same kind of function according to my requirements. as http://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing I hope, I 'll get good response.

Words are strings which are separated by dots. Two additional characters are also valid i.e:The *, which matches 1 word and the #, which matches 0..N words Example: *.stock.# matches the routing keys usd.stock and eur.stock.dsf but not stock.nasdaq.


Your help would be highly appreciated.
Sam

The only problem I see is processing the # wildcard. Other than that it's a simple matter of grabbing a word from both the pattern and the source string, then either checking them for equality or not depending on if the pattern word is a * wildcard.

Processing a # wildcard is kind of tricky if you also want to check literals beyond it. So if "#.dsf" should match "eur.stock.dsf" but not "stock.nasdaq", the algorithm needs to consider how many pattern words are remaining and not match too much when processing a # wildcard.

So maybe something like this pseudocode:

WHILE more pwords AND more swords DO
    IF pword = "#" THEN
        -- Get the next non-# pattern word
        NEXT pword WHILE pword <> "#"

        IF NOT more pwords THEN
            -- # is the last word in the pattern, so it matches everything
            RETURN true
        ELSE
            remaining := COUNT pwords

            -- Match everything up to the first remaining pattern word
            WHILE remaining > 0 AND more swords DO
                DECREMENT remaining
            LOOP

            IF remaining = 0 THEN
                -- Insufficient words in the source to match remaining pattern words
                RETURN false
            ENDIF
        ENDIF
    ELSE
        IF pword <> "*" AND sword <> pword THEN
            -- The source word doesn't match a literal pattern word
            RETURN false
        ENDIF
    ENDIF
LOOP

RETURN NOT more pwords OR more swords
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.