Regex to match only uppercase “words” with some exceptions

前端 未结 6 2038
面向向阳花
面向向阳花 2020-12-02 20:26

I have technical strings as the following:

\"The thing P1 must connect to the J236 thing in the Foo position.\"

I would like to match with

6条回答
  •  星月不相逢
    2020-12-02 21:04

    Don't do things like [A-Z] or [0-9]. Do \p{Lu} and \d instead. Of course, this is valid for perl based regex flavours. This includes java.

    I would suggest that you don't make some huge regex. First split the text in sentences. then tokenize it (split into words). Use a regex to check each token/word. Skip the first token from sentence. Check if all tokens are uppercase beforehand and skip the whole sentence if so, or alter the regex in this case.

提交回复
热议问题