Perl Regular expression | how to exclude words from a file

后端 未结 5 1631
夕颜
夕颜 2021-01-21 17:47

i searching to find some Perl Regular Expression Syntax about some requirements i have in a project. First i want to exclude strings from a txt file (dictionary).

For ex

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 18:23

    I hope someone else will come with a better solution, but this seems to do what you want:

    \b                          Match word boundary
      (?:                       Start capture group
        (?:([a-z0-9])(?!\1))*   Match all characters until it encounters a double
        (?:([a-z0-9])\2)+       Match all repeated characters until a different one is reached
      ){0,2}                    Match capture group 0 or 2 times
      (?:([a-z0-9])(?!\3))+     Match all characters until it encounters a double
    \b                          Match end of word
    

    I changed the [a-z] to also match numbers, since the examples you gave seem to also include numbers. Perl regex also has the \w shorthand, which is equivalent to [A-Za-z0-9_], which could be handy if you want to match any character in a word.

提交回复
热议问题