Regex没有正确地使用PHP,或者没有得到如何实现它

时间:2022-09-02 11:04:06

There is something really I couldn't understand is how can I check my previous match with the next character and set starting and ending character please guys help me.

有一件事我真搞不懂,那就是我怎么能查到我之前和下一个角色的匹配,然后设置开始和结束的角色请大家帮帮我。

Here is an Example of my string

这是我的字符串的一个例子

..A..B..A...B.A.B

What I'm trying to do is starting of string:

我要做的是开始弦

1=> Check the first character is .. or A

1=>检查第一个字符是。或者一个

2=> and the Second thing is String cannot be like this ..A..A it must be like ..A..B.. and sequence.

2=>,第二点是字符串不能像这样。那一定是……和序列。

3=> Ending character must be .. or B and won't be A

3=>结尾字符必须是。或者B,不是A

However, I can match the first character like so ^([A]{1}|[.]{1,100}) But when I'm trying this same way with ending character it is not working and I'm not getting how to do the step 2.

然而,我可以匹配第一个字符一样^([一]{ 1 } |[,]{ 1100 })但是,当我在这同样的方式结束字符是不工作,我没有得到如何做第2步。

Save my day guys. Thanks

拯救我的人。谢谢

Failed Regex: ^[\.{1,40}|A{1}]+(?!A)+(B)+(?!B)+(B|\.{1,40})$

失败的正则表达式:^[\。{ 1,40 } | { 1 })+(? !)+(2)+(? ! B)+(B | \。{ 1,40 })美元

1 个解决方案

#1


2  

This regex should match the description you've given:

这个regex应该与您提供的描述相匹配:

^(?:\.+?)?(A\.+?B\.?|\.\.)+$

^ is the start of the string (or line if m modifier is used).
(?:\.+?)? is one or more ., but it optional.
A\.+B\.? is looking for an A any amount of .s then a B and an optional ..
| is an alternative pattern we'll look at
\.\. are 2 .s
+ allows for the whole group to occur once or more $ is the end of the string (or line, again depends on modifier being used)

^是字符串的开始(或线如果使用m修饰符)。(?:\ + ?)?是一个或多个,但它是可选的。+ B \ \。?你要找的是任意数量的。s,然后是B和可选的。|是另一种模式,我们将看看\.\。是2 .s +允许整个组出现一次或更多$是字符串的末尾(或行,同样取决于使用的修饰符)

Demo: https://regex101.com/r/OUJxxc/3/ (Probably with a clearer description than I provided)

演示:https://regex101.com/r/OUJxxc/3/(可能比我提供的描述更清楚)

#1


2  

This regex should match the description you've given:

这个regex应该与您提供的描述相匹配:

^(?:\.+?)?(A\.+?B\.?|\.\.)+$

^ is the start of the string (or line if m modifier is used).
(?:\.+?)? is one or more ., but it optional.
A\.+B\.? is looking for an A any amount of .s then a B and an optional ..
| is an alternative pattern we'll look at
\.\. are 2 .s
+ allows for the whole group to occur once or more $ is the end of the string (or line, again depends on modifier being used)

^是字符串的开始(或线如果使用m修饰符)。(?:\ + ?)?是一个或多个,但它是可选的。+ B \ \。?你要找的是任意数量的。s,然后是B和可选的。|是另一种模式,我们将看看\.\。是2 .s +允许整个组出现一次或更多$是字符串的末尾(或行,同样取决于使用的修饰符)

Demo: https://regex101.com/r/OUJxxc/3/ (Probably with a clearer description than I provided)

演示:https://regex101.com/r/OUJxxc/3/(可能比我提供的描述更清楚)