正则表达式:仅匹配=,而不匹配==中的第一个字符

时间:2018-11-07 14:46:20

标签: regex delphi

我是regex的新手,我需要一个在=上匹配但在==上不匹配的表达式。 例如:

[x] == [y] // No match
[x] = [y] // Match

我所有的自制正则表达式都与=中的第一个==匹配。我不想要那个。如果=是表达式中唯一的运算符,我只想匹配。

我正在使用delphi正则表达式。

3 个答案:

答案 0 :(得分:0)

您必须匹配是否前任不是=和后任是否为假:

// from authClient.js

    import {AUTH_CHECK} from 'admin-on-rest';
    import Auth from './Auth'

    export default (type, params) => {
        if (type === AUTH_CHECK) {
            const auth = new Auth();
            return auth.isAuthenticated() ? Promise.resolve() : Promise.reject();
        }
        return Promise.reject('Unkown method');
    };

看看:help zo示例。 this是一个互动式教程,涵盖了重要案例。

答案 1 :(得分:0)

适应此answer应该可以解决问题:

(?:[^=]+(=)[^=]+)

说明:

(?:      // Do not capture group
[^=]+    // Match 1 or more occurrences of character other than [=]
(=)      // Match and capture a `=`
[^=]+    // Match 1 or more occurrences of character other than [=]
)        // End of group

答案 2 :(得分:0)

使用否定的lookaround

(?<!=)=(?!=)

如果没有等号,则将等号匹配。

相关问题