How to have Regex match a + symbol

How do I adjust the following Regex to match a + symbol in the 'second group'?
I'd like
1|B2 +Cnt
to return
1: 1
2: B2 +Cnt

([a-zA-Z0-9.]+)\|([0-9a-z ]+)

I appreciate any help

Same as you did with the | character -- you escape it with \ to turn off its "special meaning":

([a-zA-Z0-9.]+)\|([0-9a-z \+]+)

Note -- your regex will only work if you've got "ignoring case" turned on for the KM action, in which case you can omit the A-Z in the first match group. If you are concerned about case, you'll need to add A-Z in the second match group!

2 Likes

Like the period, the plus symbol has no special meaning inside a character class (square brackets), so you don’t need to escape it there.

This

([a-zA-Z0-9.]+)\|([0-9a-z +]+)

will also work.

Escaping the plus inside a character class doesn’t hurt, which is why @Nige_S’s solution works.

3 Likes

Will admit, I'd assumed the question was being asked because a naked "+" in the character class wasn't working for some reason. That'll teach me to test better!

1 Like

I was absolutely 100% certain of my answer but still checked at regex101.com because computers have made me doubt everything I know.

3 Likes