REGEXP_LIKE匹配逗号分隔的字符串中的特定单词

时间:2019-04-16 10:23:28

标签: regex oracle

我在数据库中有一个包含逗号分隔值的字段,我正在尝试使用REGEXP_LIKE来匹配字符串中的特定单词。

基本上,我想匹配SE这个词,但不知道如何处理。

数据库字段的值可以是:

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet'>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<style>
.container {
  position: relative;
  width: 50%;
}

.image1 {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

.image2 {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
}

.overlay {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background-color: #A4CE8C;
  overflow: hidden;
  width: 100%;
  height:0;
  transition: .5s ease;
  opacity: 0.5;
}

.container:hover .overlay {
  bottom: 0;
  height: 100%;
}

.text1 {
  white-space: nowrap; 
  color: #006400;
  font-size: 7vw;
  position: absolute;
  overflow: hidden;
  top: 25%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

.text2 {
  white-space: nowrap; 
  color: #006400;
  font-size: 7vw;
  position: absolute;
  overflow: hidden;
  top: 75%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

</style>
</head>
<body>

<div class="container col-sm-6" style="float:right; margin: 1px 0px 0px 0px; min-width: 50%;">
  <img src="C:\Users\User\Google Drive\SGroup\Website\img2re2.jpg" alt="Avatar" class="image1 img-responsive">
  <div class="overlay" >
    <div class="text1"><a href="http://safa-group.com" style="color:black; font-family: 'Raleway'; color: #006400;"><b>S Marble</b></a></div>
  </div>
</div>
<div class="container col-sm-6" style="float:left; margin: 1px 0px 0px 0px; min-width: 50%;">
  <img src="C:\Users\User\Google Drive\SGroup\Website\img1re222.jpg" alt="Avatar" class="image2 img-responsive">
  <div class="overlay">
    <div class="text2"><a href="http://safa-group.com" style="color:black; font-family: 'Raleway'; color: #006400;"><b>S Steel</b></a></div>

</div>
</div>
</body>
</html>

我尝试了以下正则表达式,但效果不佳。

"SE, SEM, NE" This should match
"SI, SE" This should match
"SI, NE" This should not match

1 个答案:

答案 0 :(得分:2)

当用0个或多个空格字符括起来时,要在逗号或字符串的开始/结尾之间匹配SE

(^|,)\s*SE\s*(,|$)
     ^^^  ^^^ 

请参见regex demoRegulex graph

enter image description here