I got values like
\w{1,2}-\w{1,2}\d{1,4} and \w{1,2}-\w{1,2} \d{1,4}
I transform these values:
AB-CD 1 -> AB-CD1
AB-CD1 -> AB-CD1
I do it using
[ ]{1}[\d]{1}
and replacing ” ” to “”. This works well.
But now I need to do the following transformation:
AB-CD1 -> AB-CD 1
AB-CD 1 -> AB-CD 1
I tried a look ahead aiming any digit
(?=\d)
but then I get two spaces if my text already contains one. I need to select the space (or none) between \w and \d – how do I do that?
You can write:
to match an optional space (i.e., either a space or the empty string) position that does not follow a digit or space and does precede a digit.
(
(?<!...)is a negative lookbehind assertion; see http://www.regular-expressions.info/lookaround.html.)