1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15const str = ` 16opQ\brstu % , jkl. 17a1 \t B!123 \n\t Hello. 18a ,,\f K 789 \n\tA42 Codex. 19123 !!!\r K 789 \n\tA42 Codex. 20a!,,\t11 ab. 21abde ,,\f K 3435 \n\tA42 Codex. 22a!,, \n\t 123Abc\rabc. 23A **,\r 123 456 a Codex. 24B?? # && abc * 90 1234! ", 25C ,,, # \t 798 76 * 100.50 ", 26` 27const regex = new RegExp('^\\w+(?<=\\w+)([^\\S]?)\\W{1,2}([!@#;:,.]{0,2})' + 28 '[\\f\\v\\r\\n\\t\\b]{1,2}\\1(\\s*\\w*\\s*)*(?<![^\\D])' + 29 '[\\uD83C-\\uDBFF\\uDC00-\\uDFFF]{2,}([^\S]?\\d+\\s*)\\w*.\\b\\w+\\.$', 'gsmiu'); 30const matches = str.match(regex); 31print(JSON.stringify(matches)); 32