Source text:
a, a, a, a
Non-working option:
/\,$/ And this is also non-working:
/,$/ But strangely, it finds the last character "a". With a comma, this does not work:
/a$/ Source text:
a, a, a, a
Non-working option:
/\,$/ And this is also non-working:
/,$/ But strangely, it finds the last character "a". With a comma, this does not work:
/a$/ The quantifier * is greedy enough to capture all the characters before the last character following it. Therefore, the expression is quite simple:
/.*,/ True, you did not indicate what to do next with the comma found, for example, we can capture it into a group .*(,) . If you want to count a comma as the whole match, then you can apply an explicit reference to the starting point of the match ( \K ), i.e. .*\K,
As for your attempt, the symbol $ means the end of a line, the expression a$ means such a letter a after which there is not a single character. ,$ accordingly expects the most recent comma, however, after it is another a therefore the expression does not fit
.*\K,.*\K, regex101.com/r/EcLAF6/1 and what didn’t suit you green - MikeMaybe do this:
(,)([^,]*$) Source: https://ru.stackoverflow.com/questions/597888/
All Articles