Regex to match only uppercase “words” with some exceptions

前端 未结 6 2037
面向向阳花
面向向阳花 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:06

    Why do you need to do this in one monster-regex? You can use actual code to implement some of these rules, and doing so would be much easier to modify if those requirements change later.

    For example:

    if(/^[A-Z0-9\s]*$/)
        # sentence is all uppercase, so just fail out
        return 0;
    
    # Carry on with matching uppercase terms
    

提交回复
热议问题