正则表达式模式找到加号和等号

时间:2018-04-24 08:39:36

标签: javascript python regex

嘿我正在寻找regex模式来搜索字符串示例:

++t+==+z++==并返回 true 如果两边都有+字母。否则其 false

  • ++t++z==将返回 false

  • ++z+p++将返回 true

  • t++z+将返回 false

js

中函数的代码示例
function check_str_pos(str){
///(\+|=|[a-zA-Z])|(\+[a-zA-Z]\+)|(\+|=|[a-zA-Z])$/

   if(/^(\+[a-zA-Z]\+)$/.test(str))
   {

  return true;
}

 else{

   return false;
  }
   }

2 个答案:

答案 0 :(得分:0)

我想,您正在寻找的RegExp是:

var reEx = new RegExp(/^\++\w*\W*\w*\++$/);

console.log(reEx.test('++t++z==')); //false
console.log(reEx.test('++z+p++'));  //true
console.log(reEx.test('t++z+'));    //false

答案 1 :(得分:0)

也许首先使用替换删除等号/// <reference path='references/_all.ts' /> var app = angular.module('shop', []); var MyController = (function () { function MyController($scope) { $scope.message = { title: "Hello World!!" }; }; return MyController; })(); app.controller('MyController', MyController); ,然后使用此模式^\++(?:[a-z]\++)+$检查剩下的内容。

这将匹配字符串=开头的+并重复^后跟[a-z]一次或多次,直到字符串{{结尾1}}。

+