-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.php
51 lines (40 loc) · 1.18 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
class SimplifiedRegex {
protected $str;
protected $pattern;
public function __construct($str) {
$this->str = $str;
$this->pattern = '';
}
public function textUppercase($length) {
$this->pattern .= "[A-Z]{{$length}}";
return $this;
}
public function dash() {
$this->pattern .= '-';
return $this;
}
public function anyNumbers() {
$this->pattern .= '\d+';
return $this;
}
public function toRegex() {
return "/{$this->pattern}/";
}
public function check() {
return preg_match($this->toRegex(), $this->str);
}
public function get() {
preg_match_all($this->toRegex(), $this->str, $matches);
return $matches[0];
}
// Add more methods as needed
}
// Example usage
$SR = new SimplifiedRegex("RI-214");
$check = $SR->textUppercase(2)->dash()->anyNumbers()->check();
echo $check ? 'True' : 'False'; // True
// Getting multiple matches
$multiSR = new SimplifiedRegex("RI-214 sdjajkgjkdhfsgdkjfjkhagkjhs, RQ-466 sakfdsjg kl;sdfgf");
$matches = $multiSR->textUppercase(2)->dash()->anyNumbers()->get();
print_r($matches); // ["RI-214", "RQ-466"]