Search code examples
regexnotepad++

Regex for wildcard connected to string


I need to match a string in which the first wildcard is not seperated from the rest of the string by a space character.

(?<=<br> ).*?【.*?】 \(.*?\)<br>

For instance, of the following example...

<br> 一を知って二を知らず see only one side of a matter; have only a narrow understanding.<br> いつ1【一】 (itsu)<br> 

... only this should be matched:

いつ1【一】 (itsu)<br> 

Currently my regex matches everything after the first <br> , irregardless of distance to the brackets . (Keep in mind the brackets are one character.)

How do you convey that the wildcard should be 'joined' with the rest of the string?


Solution

  • Not sure I understand exactly whay you need, but based on your example pattern and example output you likely want this:

    (?<=<br> )[^<]*?【[^】]*】 \([^\)]*\)<br>
    

    Match:

    いつ1【一】 (itsu)<br>
    

    Explanation:

    • (?<=<br> ) - positive lookbehind
    • [^<]*? - non-greedy scan over all non-< chars
    • 【[^】]*】 - scan over ...
    • - space char
    • \([^\)]*\) - scan over ( ... )
    • <br> - match <br>