2011-11-05 119 views

回答

5

第一招:

" 
(?!   # Assert that it is impossible to match the regex below starting at this position (negative lookahead) 
    [^&;]  # Match a single character NOT present in the list 「&;」 
     +   # Between one and unlimited times, as many times as possible, giving back as needed (greedy) 
    ;   # Match the character 「;」 literally 
) 
(?!   # Assert that it is impossible to match the regex below starting at this position (negative lookahead) 
    <   # Match the character 「<」 literally 
    [^<>]  # Match a single character NOT present in the list 「<>」 
     *   # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
) 
" 

之一:

" 
(?!   # Assert that it is impossible to match the regex below starting at this position (negative lookahead) 
    [^<>]  # Match a single character NOT present in the list 「<>」 
     *   # Between zero and unlimited times, as many times as possible, giving back as needed (greedy) 
    >   # Match the character 「>」 literally 
) 
(?!   # Assert that it is impossible to match the regex below starting at this position (negative lookahead) 
    [^&;]  # Match a single character NOT present in the list 「&;」 
     +   # Between one and unlimited times, as many times as possible, giving back as needed (greedy) 
    ;   # Match the character 「;」 literally 
) 
" 

注意,這兩個表情並沒有真正捕獲的所有東西,但他們可能是用來精確定位字符串中的位置。沒有任何上下文很難準確地說出它們在哪裏使用。

+0

非常感謝。這對我幫助很大!! – Ankur

+0

@Ankur不客氣。 – FailedDev

+0

@FailedDev你先生,是一個天才。你有一些應用程序可以用來幫助解析它,還是你只是一個正則表達式大師? – Daryl